我想这与ArrayAccess 有关,因为$this
其中的对象$this->products[$key]
确实实现了 ArrayAccess。然而,没有魔法__get
或__set
任何地方。
var_dump($this->products[$key]['selected_options'][$option_key]);
// Output: string(7) "Größe:S"
$this->products[$key]['selected_options'][$option_key] = "test";
var_dump($this->products[$key]['selected_options'][$option_key]);
// Output: string(7) "Größe:S"
有人知道这里有什么问题吗?
另请注意,这确实有效:
$this->products[$key]['selected_options'] = array($option_key => "test");
// Output: string(4) "test"
产品的 ArrayAccess 与$this
(Cart) 相同,但使用$products
而不是$data
:
class Product implements ArrayAccess
{
protected $data;
/* **** ArrayAccess **** */
public function offsetExists($offset) {
return isset($this->data[$offset]);
}
public function offsetGet($offset) {
return $this->data[$offset];
}
public function offsetSet($offset , $value) {
$this->data[$offset] = $value;
}
public function offsetUnset($offset) {
unset($this->data[$offset]);
}
}