note 116160 deleted from language.variables.basics by cmb
| From: | cmb@php.net | Date: | Sun, 28 Apr 2019 17:53:46 +0000 |
| Subject: | note 116160 deleted from language.variables.basics by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-210864@lists.php.net to get a copy of this message | ||
Note Submitter: karst at onlinq dot nl
----
From the "Properties" page, about initialising properties:
"This declaration may include an initialization, but this initialization must be a constant
value--that is, it must be able to be evaluated at compile time and must not depend on run-time
information in order to be evaluated. "
So if you define a variable in a class (as a member variable/property), things like public <?php
$test = 2+3; ?> are invalid, because logic has to be performed on the right hand side.
It HAS to be either a constant, or a scalar value (int/string/bool/float). Not even another variable
which is a constant (so <?php public $test = "test"; public $invalid = $test; ?>
would not work.
Just thought this should be mentioned here for all those like me who get here before getting to the
"Properties" page.