Bug #55731 [Bgs]: __get after __unset
| From: | 421034509 at qq dot com | Date: | Wed, 21 Sep 2011 07:42:19 +0000 |
| Subject: | Bug #55731 [Bgs]: __get after __unset | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-163742@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:
p1:
You mean __unset() made the p1 out of $example->properties?
When get_property_info successed,
zend vm return a property info with name "\0Example\0p1"
but it can't find p1 in $example->properties ?
So zend vm try to fetch "\0Example\0p1" and set a getter_guard for
"\0Example\0p1" and call getter again.
p2:
When get_property_info successed,
zend vm return a property info with name "\0Example\0p2"
and p2 can be found in $example->properties.
So zend vm wont try to fetch "\0Example\0p1" but successed and return p2?
Previous Comments:
------------------------------------------------------------------------
[2011-09-21 03:32:28] laruence@php.net
p2 is a litte different, see blow:
1. you call $example->p2
2. zend vm call read_propery , in which internal will check property_info and socpe, since this
is called out from example->ce, so get_property_info will deny and return NULL, then zend vm
assume you are try to access a public "p2"()
3. so zend vm set a getter_guard for "p2" and call getter try to find "p2"
(output
"call_get()!")
4. in your custom getter, you fetch $example->p2
5. zend vm call read_property, the first begining is similar to the situation when you trying to
fetch p1, but, zend vm
find p2 in $example->properties(this it the key difference), then suceed and return.
------------------------------------------------------------------------
[2011-09-21 00:48:39] 421034509 at qq dot com
Thanks for your explain,but there is something I still can't understand.
In 2:what's the "called out from $Example->ce" mean?
(Sorry!My English is poor and I have studied PHP a short time)
Do you mean I call $example->p1 out of the class?
If so,I call $example->p2 out of the class too.
Then,in my custom getter, I attempt fetch $this->p2.
in this case, it attempt to access p2 in example class scope ,
why dosn't it call getter again?
Can you explain why $example->p2 call getter only once for me like before?
------------------------------------------------------------------------
[2011-09-20 09:42:43] laruence@php.net
I have give you a example which will only call get once after unset, and okey, if you want a
more specific explain, here we go:
1. you call $example->p1
2. zend vm call read_propery , in which internal will check property_info and socpe, since this
is called out from example->ce, so get_property_info will deny and return NULL, then zend vm
assume you are try to access a public "p1"()
3. so zend vm set a getter_guard for "p1" and call getter try to find "p1"
(output
"call_get()!")
4. in your custom getter, you attempt fetch $this->p1
5. in this case, you attempt to access p1 in example class scope , so get_property_info
successed, and return a property info with name "\0Example\0p1"
5. zend vm try to fetch "\0Example\0p1" now, set a getter_guard for
"\0Example\0p1" and call
getter again (output "call_get()!")
7. zend vm found call getter in getter(by gettter_guard which was setted in 5), then give up,
and return.
------------------------------------------------------------------------
[2011-09-20 08:47:14] 421034509 at qq dot com
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"?
------------------------------------------------------------------------
[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;
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=55731
--
Edit this bug report at https://bugs.php.net/bug.php?id=55731&edit=1