Functions & References

From: Date: Thu, 03 Feb 2000 23:33:05 +0000
Subject: Functions & References
Groups: php.dev 
Request: Send a blank email to php-dev+get-15179@lists.php.net to get a copy of this message
I have summed a list of possible ways to export a referenced argument outside a function, but it doesn't seem to work. * If this has been asked a million times before, please don't flame me :) * If you know a workaround or sollution or "it will be fixed in the next version", please keep in mind that I'me not a member of this mailing list. (mail me please!) - Vincent Vollers PS: I'me using PHP4 Beta 3 with Apache on a Linux (RedHat 6.2) machine -- snip -- <?php // I try to create a reference in a function and I wish to KEEP that reference // (somehow) outside the function. $aglobalvar = "testing3"; function test(&$argument,&$referencedArgument) { global $aglobalvar; global $$aglobalvar; $referencedArgument = &$argument; $aglobalvar = &$argument; echo "(inside function): " . $referencedArgument . " <BR> "; $referencedArgument = "not initial value"; echo "(inside function -changed- ): " . $referencedArgument . " <BR> "; return array($referencedArgument); } $string0= "initial value"; $string1 = "Testing 1"; $string2 = "Testing 2"; list($string2)=test($string0,$string1); // I want $string1 to reference to $string0 echo "(testing3): " . $testing3 . "<BR>"; // Wrong (bug?) (doesn't even return a copy) echo "(array var): " . $string2 . "<BR>"; // OK (well at least it's a -copy-) echo "(referenced var): " . $string1 . "<BR>"; // Wrong (Bug?) (doesn't return a copy) $string1 = "Something Else"; // In theory this should reference to $string0 echo "(string0 (1) ): " . $string0 . "<BR>"; // So this should be "Something Else" $string2 = "This Works"; // This also. :( echo "(string0 (2) ): " . $string0 . "<BR>"; // $aglobalvar = "This is supposed to work?"; // And this should do it as well. echo "(string0 (3) ): " . $string0 . "<BR>"; // // The weird part is, the reference is not broken INSIDE the function, that part works, // but whenever i export it (somehow) it gets broken, it's driving me crazy!!! // - Vincent Vollers ?>

« previous php.dev (#15179) next »