Fwd: [PHP-DEV] Is it possible to get the variable name from the HashTable structure?
| From: | Aaron Lewis | Date: | Sun, 04 May 2014 15:54:32 +0000 |
| Subject: | Fwd: [PHP-DEV] Is it possible to get the variable name from the HashTable structure? | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-73875@lists.php.net to get a copy of this message | ||
FWD I forgot to CC the list ;-(
---------- Forwarded message ----------
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 )
On Sun, May 4, 2014 at 11:46 PM, Johannes Schlüter
<johannes@schlueters.de> wrote:
> On Sun, 2014-05-04 at 16:13 +0100, Joe Watkins wrote:
>> On Sun, 2014-05-04 at 20:21 +0800, Aaron Lewis wrote:
>> > Hi,
>> >
>> > So PHP uses HashTable to store variables like $_POST,
>> >
>> > From a HashTable structure, can I get the array name?
>
> No, a zval (which might point to a hash tale) doesn't refer to a name.
> For one there in 99.99% is no need but it would cost memory(and CPU
> cycles to maintain) and then there miht e multiple nae (references) or
> none (temporaries etc.)
>
> If you know the parent such hacks like
>
>> https://gist.github.com/krakjoe/50603be7ffb1ae6e9156
>
> might work, but even this solution is flawed: The easy thing it doesn't
> support is references, it should return an array of all names. It won't
> work for complex things, though.
>
> If you need such a functionality I'd suggest to take a step back and
> think what you actually want to do ... usually there is a better
> solution.
>
> johannes
>
>
--
Best Regards,
Aaron Lewis - PGP: 0x13714D33 - http://pgp.mit.edu/
Finger Print: 9F67 391B B770 8FF6 99DC D92D 87F6 2602 1371 4D33
--
Best Regards,
Aaron Lewis - PGP: 0x13714D33 - http://pgp.mit.edu/
Finger Print: 9F67 391B B770 8FF6 99DC D92D 87F6 2602 1371 4D33