note 15393 added to language.variables
| From: | audiosculptor at _NO_SPAM_hotmail dot com | Date: | Fri, 07 Sep 2001 19:49:59 +0000 |
| Subject: | note 15393 added to language.variables | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-17787@lists.php.net to get a copy of this message | ||
(James Munroe) In the example given by cjdesigns@sprintmail.com (accessing variables from within
subfunctions), the function and subfunction must actually be called in order for the variable to be
displayed; laso, the subfunction call must appear <i>after</i> the subfunction
definition (there's no forward referencing within a function definition). The call to the
enclosing funciton, however, in the main block of code can appear before its definition. Thus, the
code should look like this:
<PRE>
<?php
$A = 1;
foo();
function foo() {
$A = 2;
function subfoo() {
global $A;
echo $A;
}
subfoo();
}
?>
</PRE>
The output will look like this:
<PRE>1</PRE>
http://www.php.net/manual/en/language.variables.php