Skip to content

Instantly share code, notes, and snippets.

@cockok
Last active August 29, 2015 13:59
Show Gist options
  • Save cockok/10713963 to your computer and use it in GitHub Desktop.
Save cockok/10713963 to your computer and use it in GitHub Desktop.
Indirect modification of overloaded property Hoge::$hage has no effect in ...
<?php
class Hoge {
private $data = array();
public function __get($key) {
return array_key_exists($key, $this->data) ? $this->data[$key] : null;
}
public function __set($key, $value) {
return $this->data[$key] = $value;
}
}
$hoge = new Hoge();
$hoge->hage = array(1);
$hoge->hage[0] = 2;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment