3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private $allowedNames = ['onlyThis', 'andThat']; public function __set($name, $value) { // only allow specific properties to be set pubically if (!in_array($name, $this->allowedNames)) { throw new Exception("No! Bad dog!"); } else { $this->$name = $value; } } } $foo = new Foo; $foo->onlyThis = true; $foo->andThat = false; var_dump($foo); // This won't work $foo->baz = 1;

preferences:
69.36 ms | 402 KiB | 5 Q