Declare the variable outside of scope of b and a (if you don't want to
use $_GLOBALS directly).
<?php
if (!$argc) ob_start('nl2br'); // trick to get stuff to print nicely
on either web/cli output
$thing = 1;
function a() {
global $thing;
b(2);
}
function b($newThing) {
global $thing;
$thing = $newThing;
}
echo "$thing\n";
a();
echo "$thing\n";
b(10);
echo "$thing\n";
?>
In OO style there is no 'friend' in PHP, which is a good thing.
On 26/06/2009, at 8:13 PM, Michael wrote:
>
> We all know that we can make a static variable in to a global, but
> how do I
> make a dynamic variable into a global?
>
> I am calling a function (b), from with a function (a) and I want
> function b to
> have a dynamic value from function a IN THIS MANNER.
>
> Specifying that as a global in either or both functions a and b
> doesn't seem
> to work.
>
> Michael
>
> >
--~--~---------~--~----~------------~-------~--~----~
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[email protected]
-~----------~----~----~----~------~----~------~--~---