Skip to main content
added 42 characters in body
Source Link
bwoebi
  • 1.7k
  • 1
  • 10
  • 20

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);

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);
        return ob_get_clean()[29];
    }
}

$obj = new State;
var_dump($obj->state);
$a = $obj;
var_dump($obj->state);

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);
Source Link
bwoebi
  • 1.7k
  • 1
  • 10
  • 20

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);
        return ob_get_clean()[29];
    }
}

$obj = new State;
var_dump($obj->state);
$a = $obj;
var_dump($obj->state);