note 98811 added to language.variables.scope
| From: | HOSSEINdoesn' | Date: | Fri, 09 Jul 2010 07:26:02 +0000 |
| Subject: | note 98811 added to language.variables.scope | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-170807@lists.php.net to get a copy of this message | ||
Please note for using global variable in child functions:
This won't work correctly...
<?php
function foo(){
$f_a = 'a';
function bar(){
global $f_a;
echo '"f_a" in BAR is: ' . $f_a . '<br />'; // doesn't
work, var is empty!
}
bar();
echo '"f_a" in FOO is: ' . $f_a . '<br />';
}
?>
This will...
<?php
function foo(){
global $f_a; // <- Notice to this
$f_a = 'a';
function bar(){
global $f_a;
echo '"f_a" in BAR is: ' . $f_a . '<br />'; // work!, var is
'a'
}
bar();
echo '"f_a" in FOO is: ' . $f_a . '<br />';
}
----
Server IP: 69.147.83.197
Probable Submitter: 188.158.165.233
----
Manual Page -- http://www.php.net/manual/en/language.variables.scope.php
Edit -- https://master.php.net/note/edit/98811
Del: integrated -- https://master.php.net/note/delete/98811/integrated
Del: useless -- https://master.php.net/note/delete/98811/useless
Del: bad code -- https://master.php.net/note/delete/98811/bad+code
Del: spam -- https://master.php.net/note/delete/98811/spam
Del: non-english -- https://master.php.net/note/delete/98811/non-english
Del: in docs -- https://master.php.net/note/delete/98811/in+docs
Del: other reasons-- https://master.php.net/note/delete/98811
Reject -- https://master.php.net/note/reject/98811
Search -- https://master.php.net/manage/user-notes.php