Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can't with the current implementation. In order for this to work, you will have to create an array object (i.e.: an object that implements <code>ArrayAccess</code>). Something like:</p> <pre><code>class SuperArray implements ArrayAccess { protected $_data = array(); protected $_parents = array(); public function __construct(array $data, array $parents = array()) { $this-&gt;_parents = $parents; foreach ($data as $key =&gt; $value) { if (is_array($value)) { $value = new SuperArray($value, array_merge($this-&gt;_parents, array($key))); } $this[$key] = $value; } } public function offsetGet($offset) { if (!empty($this-&gt;_parents)) echo "['".implode("']['", $this-&gt;_parents)."']"; echo "['$offset'] is being accessed\n"; return $this-&gt;_data[$offset]; } public function offsetSet($offset, $value) { if ($offset === '') $this-&gt;_data[] = $value; else $this-&gt;_data[$offset] = $value; } public function offsetUnset($offset) { unset($this-&gt;_data[$offset]); } public function offsetExists($offset) { return isset($this-&gt;_data[$offset]); } } class Test{ protected $foo; public function __construct() { $array['bar']['hello'] = 'world'; $this-&gt;foo = new SuperArray($array); } public function __get($name){ echo $name.' is being accessed.'.PHP_EOL; return $this-&gt;$name; } } $test = new Test; echo $test-&gt;foo['bar']['hello']; </code></pre> <p>Should output:</p> <pre><code>foo is being accessed. ['bar'] is being accessed ['bar']['hello'] is being accessed world </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload