Search code examples
phpstringclassconcatenationphp-5.2

PHP string concatenation within class definition


Possible Duplicate:
Initializing PHP class property declarations with simple expressions yields syntax error

Is it possible to achieve the following in PHP 5.2.17 ?

$basePath = '/final';

class Foo {
    public $data = $basePath . '/data';
}

Solution

  • The default values for properties must be constant in the source, e.g. strings and array literals. No expressions.

    Use the __construct() method for anything more complicated.