Re: [PHP4BETA] Self-referencing variables revisited

From: Date: Tue, 28 Mar 2000 17:21:09 +0000
Subject: Re: [PHP4BETA] Self-referencing variables revisited
References: 1 2 3 4  Groups: php.version4 
Request: Send a blank email to php-version4+get-12756@lists.php.net to get a copy of this message
Andrei Zmievski wrote: > On Tue, 28 Mar 2000, Gary Bickford wrote: > > I don't find get_class_name() in the manual yet. Does it also support > > arrays and simple objects (not classes)? > > No, when you call a function like foo($bar), it does not know anything > about the name of the variable that was passed, only its value. Exactly my point. With nameof(), one could do one of the following, depending on the implementation internals of PHP: <? function foo(&$bar) { // Call by reference required printf ("%s: %s",nameof($bar), $bar); } $somevar="toast"; foo($somevar); ?> which would output "somevar: toast" or <? function ($barname) { global $$barname; printf(%s: %s", $barname, $$barname); } $barname=nameof($somevar); foo($barname); ?> with the same output

« previous php.version4 (#12756) next »