- var_dump: documentation ( source)
- trigger_error: documentation ( source)
<?php
class A{
private $__props = ["a"];
function __get($prop){
if(\array_key_exists($prop, $this->__props)){
return $this->__props[$prop];
}
}
function __set($prop, $value){
if($prop === "a"){
if($value > 100){
$this->__props[$prop] = $value;
} else {
trigger_error('Invariant "$this->a > 100" violated');
}
}
}
}
$a = new A();
$a->a = 110;
$b = &$a->a;
$b = "hello";
var_dump($a,$b);