note 15393 deleted from language.variables by irc-html
| From: | irc-html@php.net | Date: | Sat, 19 Jan 2002 18:48:13 +0000 |
| Subject: | note 15393 deleted from language.variables by irc-html | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-25184@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>