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

From: Date: Tue, 28 Mar 2000 22:37:16 +0000
Subject: Re: [PHP3] Re: [PHP4BETA] Self-referencing variables revisited
References: 1 2 3 4 5 6  Groups: php.version4 
Request: Send a blank email to php-version4+get-12770@lists.php.net to get a copy of this message
Well, I don't have the solution, but I think that in Prolog you could reference yourself! Anyway, it could be implemented in PHP, but with a language structure/array/class. My idea is along the lines of $HTTP_POST_VARS array. I mean you could have a bunch of arrays, like: $PHP_RUNTIME_VARS, $PHP_RUNTIME_FUNCTIONS, $PHP_RUNTIME_CLASSES. Arrays are associative, so you could address, for example, $PHP_RUNTIME_FUNCTIONS['foobar']. Better yet, the $PHP_RUNTIME_* could be classes so that you can inspect and modify their values on the fly. That could lead...to dynamic class generation???? Why should anybody need it, is another question:-) But you could build nice debuggers with such stuff. Hmmm, how about generating your code or your class from database stored text? Just an idea. -Stathis. NickM wrote: > > 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 -- +-----------------------------+ |Rouvas Stathis | |University of Athens | |Department of Informatics | |http://www.di.uoa.gr/~rouvas | |rouvas@di.uoa.gr | +-----------------------------+

« previous php.version4 (#12770) next »