note 107282 added to language.variables.scope
| From: | marc | Date: | Fri, 27 Jan 2012 06:23:21 +0000 |
| Subject: | note 107282 added to language.variables.scope | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-185761@lists.php.net to get a copy of this message | ||
<?php
function foo(){
static $int = 0; // correct
static $int = 1+2; // wrong (as it is an expression)
static $int = sqrt(121); // wrong (as it is an expression too)
$int++;
echo $int;
}
?>
Please update this example it is not completely correct, it can be confusing.
<?php
function foo(){
static $int = 0; // correct
static $int = 1+2; // wrong (as it is an NON-CONSTANT expression)
static $int = sqrt(121); // wrong (as it is an NON-CONSTANT expression too)
$int++;
echo $int;
}
?>
Expressions can be assigned to static variables, they just have to be constants, nothing dynamic, no
calculations etc
----
Server IP: 69.147.83.197
Probable Submitter: 118.68.192.21
----
Manual Page -- http://www.php.net/manual/en/language.variables.scope.php
Edit -- https://master.php.net/note/edit/107282
Del: integrated -- https://master.php.net/note/delete/107282/integrated
Del: useless -- https://master.php.net/note/delete/107282/useless
Del: bad code -- https://master.php.net/note/delete/107282/bad+code
Del: spam -- https://master.php.net/note/delete/107282/spam
Del: non-english -- https://master.php.net/note/delete/107282/non-english
Del: in docs -- https://master.php.net/note/delete/107282/in+docs
Del: other reasons-- https://master.php.net/note/delete/107282
Reject -- https://master.php.net/note/reject/107282
Search -- https://master.php.net/manage/user-notes.php