note 120112 added to language.variables.scope
| From: | simon dot barotte at gmail dot com | Date: | Thu, 03 Nov 2016 10:46:21 +0000 |
| Subject: | note 120112 added to language.variables.scope | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-207007@lists.php.net to get a copy of this message | ||
To be vigilant, unlike Java or C++, variables declared inside blocks such as loops (for, while,...)
or if's, will also be recognized and accessible outside of the block, the only valid block is
the BLOCK function so:
<?php
for($j=0; $j<5; $j++)
{
if($j == 1){
$a = 6;
}
}
echo $a;
?>
Would print 6.
----
Server IP: 72.52.91.14
Probable Submitter: 109.190.128.177
----
Manual Page -- http://php.net/manual/en/language.variables.scope.php
Edit -- https://master.php.net/note/edit/120112
Del: integrated -- https://master.php.net/note/delete/120112/integrated
Del: useless -- https://master.php.net/note/delete/120112/useless
Del: bad code -- https://master.php.net/note/delete/120112/bad+code
Del: spam -- https://master.php.net/note/delete/120112/spam
Del: non-english -- https://master.php.net/note/delete/120112/non-english
Del: in docs -- https://master.php.net/note/delete/120112/in+docs
Del: other reasons-- https://master.php.net/note/delete/120112
Reject -- https://master.php.net/note/reject/120112
Search -- https://master.php.net/manage/user-notes.php