On 28 July 2004 12:29, Frank Munch wrote: > Would anyone know how to resolve this scope problem? Or is > this possibly > something PHP can't (yet) do? > > The problem is to access a variable in a function foo from a function > local to foo.
Actually, your problem is that the function bar is *not* local to foo. Even though PHP lets you declare functions lexically within the scope of other functions, semantically they are still global functions and have no access whatsoever to the enclosing function. > > - - - > > function foo($var_foo) > { > $my_foo_local = 10; //How can I reach this from inside function > bar(...? > > function bar($var_bar) > { > return $my_foo_local+$var_bar+1; // Doesn't work, can't see > $my_foo_local } > > return bar($var_foo)+1; > } > > if (foo(0)==12) > echo "Yes! I did it!"; > else > echo "Nope. Sorry"; Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php