<?php
/**
* @property stdClass $x
* @property stdClass $y
*/
class C {
private $buffer = array();
function __get($key) {
if (array_key_exists($key, $this->buffer)) {
return $this->buffer[$key];
}
$f = 'calc_' . $key;
return $this->buffer[$key] = $this->$f();
}
function calc_x() {
$x = new stdClass;
$x->y = $this->y;
return $x;
}
function calc_y() {
$y = new stdClass;
// Set a stub to avoid infinite recursion.
$this->buffer['y'] = $y;
$y->x = $this->x;
return $y;
}
}
$c = new C;
$c->x;
$c = new C;
$c->y;
- Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
- Warning: Undefined property: C::$x in /in/00Kuv on line 28
Warning: Undefined property: C::$y in /in/00Kuv on line 20
- Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.38, 7.0.0 - 7.0.33, 7.1.5 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
- Notice: Undefined property: C::$x in /in/00Kuv on line 28
Notice: Undefined property: C::$y in /in/00Kuv on line 20
- Output for 7.3.32 - 7.3.33
- Output for 7.1.0 - 7.1.4
- Notice: Undefined property: C::$y in /in/00Kuv on line 20
preferences:
224.25 ms | 401 KiB | 294 Q