note 116160 added to language.variables.basics
| From: | karst at onlinq dot nl | Date: | Mon, 17 Nov 2014 11:34:04 +0000 |
| Subject: | note 116160 added to language.variables.basics | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-200924@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 72.52.91.14
Probable Submitter: 88.159.23.235
----
Manual Page -- http://php.net/manual/en/language.variables.basics.php
Edit -- https://master.php.net/note/edit/116160
Del: integrated -- https://master.php.net/note/delete/116160/integrated
Del: useless -- https://master.php.net/note/delete/116160/useless
Del: bad code -- https://master.php.net/note/delete/116160/bad+code
Del: spam -- https://master.php.net/note/delete/116160/spam
Del: non-english -- https://master.php.net/note/delete/116160/non-english
Del: in docs -- https://master.php.net/note/delete/116160/in+docs
Del: other reasons-- https://master.php.net/note/delete/116160
Reject -- https://master.php.net/note/reject/116160
Search -- https://master.php.net/manage/user-notes.php