$method = get{$property}; return ( method_exists( $this, $method ) ); } function getname() {
return bob; } function getage() { return 44; }}print ;
$p = new person();if ( isset( $p->name ) ) { print $p->name;} else { print nope\n;}print ;// output: // bob?>
复制代码
演示代码2:
$method( $value ); } } function __unset( $property ) { $method = set{$property}; if ( method_exists( $this, $method ) ) { $this->$method( null ); } } function setname( $name ) { $this->_name = $name; if ( ! is_null( $name ) ) { $this->_name = strtoupper($this->_name); } } function setage( $age ) {
$this->_age = $age; }}print ;
$p = new person();$p->name = bob;$p->age = 44;print_r( $p );unset($p->name);print_r( $p );print ;?>
复制代码
输出结果:person object( [_name:person:private] => bob [_age:person:private] => 44)person object( [_name:person:private] => [_age:person:private] => 44)
