- var_dump: documentation ( source)
- in_array: documentation ( source)
<?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;