S
S
Sergey Pugovkin2017-08-15 22:50:21
PHP
Sergey Pugovkin, 2017-08-15 22:50:21

How to track not only the name of the property, but also the name of the key - __get ()?

<?php
class Example
{
    public function __get($name)
    {
        var_dump($name);
    }
}
$a = new Example;
$a->abc['k'];

displays "abc". How to get 'dd'? Those. how to track not only the property name, but also the key name?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav B, 2017-08-16
@Driver86

When you do $a->abc['k']
it is all executed in the following sequence ($a->__get('abc'))['k']
That is, no key is passed to the get.
And I'm 99% sure you don't really need it. What you are trying to do is black magic, for which no one will thank you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question