Я пришел, потому что хотел знать об этом.
После того, как я увидел ответ Хавенарда и затем проверил его, я обнаружил.
class A implements \ArrayAccess
{
private $array;
public function __construct()
{
$this->array = array("one"=>1, "two"=>2, "three"=>3);
}
public function WhatDoesThisArray($val1)
{
$this[$val1] = 99;
$this[$val1];
var_dump($this[$val1]);
echo $this[$val1];
}
public function offsetExists($offset)
{
echo "call offsetExists\n";
}
public function offsetGet($offset)
{
echo "call offsetGet($offset)\n";
return $this->array[$offset];
}
public function offsetUnset($offset)
{
echo "call offsetUnset\n";
}
public function offsetSet($offset, $value)
{
echo "call offsetSet\n";
$this->array[$offset] = $value;
}
}
/* Test */
$testClass = new A();
$testClass->WhatDoesThisArray("two");
/* Result */
call offsetSet
call offsetGet(two)
call offsetGet(two)
int(99)
call offsetGet(two)
99
в классе, подобном [Класс AImplements \ ArrayAccess]
$ this [$ var]; означает $ this-> offsetGet ($ var);
$ this [$ var] = $ value; означает $ this-> offsetSet ($ var, $ value);
Надеюсь, это помогло.Спасибо, Хавенард!