-1

Normally i wouldn't post syntax errors here, but this case is a bit suspicious to me. I was trying to put together a constant with a string. I works fine on localhost, but when i push my project on my web server, it tells me:

Parse error: syntax error, unexpected '.', expecting ',' or ';' in xxx on line xxx

Code:

define("ROOT", str_replace("index.php", "", $_SERVER["SCRIPT_FILENAME"]));

and

$somePath = ROOT . "some/path"; //Synax error in this line

Has this something to do with different PHP versions? (5.5 on webserver, 7.0 localhost)

Update

Some updates in the code:

class SomeClass {

    private $somePath = ROOT . "some/path"; //Synax error in this line

    ...
}
PrototypeX7
  • 154
  • 2
  • 10

1 Answers1

0

You can't use str_replace() nor any function when defining a contant. Try:

define("ROOT", $_SERVER["SCRIPT_FILENAME"]);
$somePath = str_replace("index.php", "", ROOT) . "some/path";

Please refer to PHP Manual:

In PHP 5, value must be a scalar value (integer, float, string, boolean, or NULL). In PHP 7, array values are also accepted.

Al Foиce ѫ
  • 4,195
  • 12
  • 39
  • 49