这是我非常迅速地掀起的一些东西,以展示当这样的事情发生时你如何能够触发错误:
error_reporting( E_ALL | E_STRICT );
class Joe {
public $lastName;
public function __set( $name, $value ) {
if ( !property_exists( $this, $name ) ) {
trigger_error( 'Undefined property via __set(): ' . $name, E_USER_NOTICE );
return null;
}
$this->$name = $value;
}
public function __get( $name ) {
if ( !property_exists( $this, $name ) ) {
trigger_error( 'Undefined property via __get(): ' . $name, E_USER_NOTICE );
return null;
}
return $this->$name;
}
}
$joe = new Joe();
$joe->lastNom = "Smith";
echo $joe->lastNom , "\n";
?>