您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHP中__set 与 __get使用示例

2024/3/22 13:02:17发布12次查看
$method(); } } function __isset( $property ) {
$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)
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product