PHP对象的在函数间传递
<?php class UserProfile { private $userinfo = array(); public function __set( $name, $value ) { $this->userinfo[$name] = $value; } public function __get( $name ) { if ( array_key_exists( $name, $this->userinfo ) ) { return $this->userinfo[$name]; }else { return null; } } public function __isset( $name ) { return isset( $this->userinfo[$name] ); } } function fun1($a) { //这里$a前加&不加&结果一样 fun2($a); } function fun2($a) { fun3($a); } function fun3($a) { $a->username = "jishipu"; } $userprofile = new UserProfile(); fun1($userprofile); var_dump($userprofile); ?>
输出结果:
object(UserProfile)#1 (1) { ["userinfo:private"]=> array(1) { ["username"]=> string(7) "jishipu" } }
php对象是按照地址进行传递的
相关推荐
- memcache的increment用法
- Posted on 02月15日
- 拒绝过度舒适
- Posted on 04月03日
- 超级服务inetd和xinetd
- Posted on 05月13日
- Mysql INSERT DELAYED语法
- Posted on 02月14日