PHP (debug build, >= 5.4)
We use refcount of the object in a getter. (So, by the assignment, refcount increases and value changes)
class State {
public function __get($arg) {
ob_start();
debug_zval_dump($this); // e.g. "object(State)#1 (0) refcount(6)"
return ob_get_clean()[29];
}
}
$obj = new State;
var_dump($obj->state);
$a = $obj;
var_dump($obj->state);