Bug #55731 [Bgs]: __get after __unset
| From: | 421034509 at qq dot com | Date: | Tue, 20 Sep 2011 08:47:14 +0000 |
| Subject: | Bug #55731 [Bgs]: __get after __unset | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-163706@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=55731&edit=1
ID: 55731
User updated by: 421034509 at qq dot com
Reported by: 421034509 at qq dot com
Summary: __get after __unset
Status: Bogus
Type: Bug
Package: Unknown/Other Function
Operating System: windows xp
PHP Version: 5.3.8
Block user comment: N
Private report: N
New Comment:
I want to know what happened after __unset.
$example->p1 has bean unset and $example->p2 is never set.
But isset($example->p1)) and isset($example->p2)) are all false.
Why $example->p2 call __get once but $example->p1 call __get twice?
What's the diference of the $example->p1 which has bean unset and the $example->p2 which
is never set"?
Previous Comments:
------------------------------------------------------------------------
[2011-09-20 04:07:07] laruence@php.net
see blow, and I think you will find out the reason:
<?php
class Example{
private $p1;
function __construct($a){
$this->p1=$a;
}
function __get($elmname){
echo "Call_get()!"; //In order to follow the method __get()
}
function __unset($name){
unset($this->$name);
}
}
$example = new Example("v1");
unset($example->p1);
echo $example->p1;
------------------------------------------------------------------------
[2011-09-20 02:35:23] 421034509 at qq dot com
Description:
------------
<?php
class Example{
private $p1;
private $p2;
function __construct($a){
$this->p1=$a;
}
function __get($elmname){
echo "Call_get()!"; //In order to follow the method __get()
return $this->$elmname;
}
function __isset($name){
return isset($this->$name);
}
function __unset($name){
unset($this->$name);
}
}
$example=new Example("v1","v2");
echo $example->p1."<br/>";
var_dump(isset($example->p2));//p2 is uninitialized,the result is bool(false)
echo $example->p2;//This time,__get is called by 1 time.
unset($example->p1);
var_dump(isset($example->p1));//Because of __unset,the result is bool(false)
echo $example->p1;//Amazingï¼I call the __get just once,but it seems that the __get method
has bean called two times!
?>
Expected result:
----------------
Call_get()! v1
bool(false) Call_get()ï¼bool(false) Call_get()ï¼
Actual result:
--------------
Call_get()! v1
bool(false) Call_get()ï¼bool(false) Call_get()ï¼Call_get()ï¼
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=55731&edit=1