Re: Fwd: [PHP-DEV] Is it possible to get the variable name from the HashTable structure?

From: Date: Sun, 04 May 2014 17:34:22 +0000
Subject: Re: Fwd: [PHP-DEV] Is it possible to get the variable name from the HashTable structure?
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-73877@lists.php.net to get a copy of this message
On Sun, 2014-05-04 at 23:54 +0800, Aaron Lewis wrote: > Here's what I want, > > If a user runs code like this, and $_GET['MH'] happens to be > undefined, I want to know both '_GET' and 'MH': > > if ($_GET['MH'] == 'dog') > { > do-something > } > > But so far I can only get the 'MH' part ( I checked the 'Undefined > index' part in a zend function, can't remember the exact name ) What do you want to achieve? Some developer tool for better messages? For the general case of $someVar->method()['key1']['key2'] == 'baz' there is no good solution (well, you could try to analyze the current opcode array, try to find current opline in there and do magic, but that's quite crazy and notable effort) For the simple case you can look at Joe's example on how to iterate over the current symbol table, and if need be combine that with a recursive search (mind infinite recursion caused by references) but there the effort makes it questionable whether the information gained brings value ... johannes

« previous php.internals (#73877) next »