Re: [PHP3] Re: [PHP4BETA] Self-referencing variables revisited

From: Date: Tue, 28 Mar 2000 21:10:20 +0000
Subject: Re: [PHP3] Re: [PHP4BETA] Self-referencing variables revisited
References: 1 2 3 4 5  Groups: php.version4 
Request: Send a blank email to php-version4+get-12768@lists.php.net to get a copy of this message
You can't do that in any language I can think of, that is nothing to do with the language. When you pass a variable to a function the function gets a copy of the variable unless passed by reference in which case it gets a pointer, it knows nothing of the name or what goes on in it's namespace. I mean what when you call debug(2), what is it supposed to calculate for that. If you want name info with the debug then just do: debug($var, "var info"); I'm sure in most cases you will know what you are working with anyway though, how much info are you debugging. I usually have a static string placed before the variable in my debug function, just so you know that it is not part of the normal logs. If it is crucial then at best you could make sure the variable is global and send the name to debug which will then be able to fetch the data from the global stack. Nick ----- Original Message ----- From: "Gary Bickford" <garyb@fxt.com> To: "Andrei Zmievski" <andrei@ispi.net> Cc: <php4beta@lists.php.net>; <php3@lists.php.net> Sent: Tuesday, March 28, 2000 7:21 PM Subject: [PHP3] Re: [PHP4BETA] Self-referencing variables revisited > 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 > > > -- > PHP 3 Mailing List <http://www.php.net/> > To unsubscribe, send an empty message to php3-unsubscribe@lists.php.net > To subscribe to the digest, e-mail: php3-digest-subscribe@lists.php.net > To search the mailing list archive, go to: http://www.php.net/mailsearch.php3 > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.version4 (#12768) next »