Cannot use concatenation when declaring class properties by default in PHP?

When declaring default values ​​for properties in a PHP class, it seems like you cannot use concatenation. Is there a reason for this?

class Foo
{
    public $property = __DIR__ . '/';
}
+5
source share
2 answers

For PHP versions up to 5.6

See http://www.php.net/manual/en/language.oop5.properties.php

public, protected private, . , , .

public function __construct()
{
    $this->settings = __DIR__ . '/';
}

PHP 5.6

PHP 5.6 PHP. . https://wiki.php.net/rfc/const_scalar_exprs.

, ( const, , ..), .

+8

__constructor. php5. $this- > class_name() php4.

0

All Articles