note 98811 deleted from language.variables.scope by crell
| From: | crell@php.net | Date: | Thu, 31 Mar 2022 19:49:16 +0000 |
| Subject: | note 98811 deleted from language.variables.scope by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-217941@lists.php.net to get a copy of this message | ||
Note Submitter: HOSSEIN doesn't want spam at TAKI.IR
----
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 />';
}
?>