[PHP-BUG] Bug #55746 [NEW]: issue with __get on unset property

2011-09-20 Thread hytest at gmail dot com
From: 
Operating system: Fedora 15
PHP version:  5.3.8
Package:  *General Issues
Bug Type: Bug
Bug description:issue with __get on unset property 

Description:

Test following script please. 
It enters __get twice on unset property (class Ex1) but only once on Ex2. 

It doesn't really make sense and can't find any word in document so I
assume it's 
a bug. 

Test script:
---
class Ex1{
  private $var;

  function __construct(){
unset($this->var);
  }

  function __get($elmname){
echo "call __get\n";
return $this->$elmname;
  }

}

class Ex2{

function __construct(){
}

function __get($elmname){
echo "call __get\n";
return $this->$elmname;
}

}

$ex1=new Ex1();
echo $ex1->var;

$ex2=new Ex2();
echo $ex2->var;


Expected result:

call __get
PHP Notice:  Undefined property: Ex1::$var in /web/sites/test/test1/t5.php
on line 
12
call __get
PHP Notice:  Undefined property: Ex2::$var in /web/sites/test/test1/t5.php
on line 
24


Actual result:
--
call __get
call __get
PHP Notice:  Undefined property: Ex1::$var in /web/sites/test/test1/t5.php
on line 
12
call __get
PHP Notice:  Undefined property: Ex2::$var in /web/sites/test/test1/t5.php
on line 
24


-- 
Edit bug report at https://bugs.php.net/bug.php?id=55746&edit=1
-- 
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=55746&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=55746&r=trysnapshot53
Try a snapshot (trunk):  
https://bugs.php.net/fix.php?id=55746&r=trysnapshottrunk
Fixed in SVN:
https://bugs.php.net/fix.php?id=55746&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=55746&r=needdocs
Fixed in release:
https://bugs.php.net/fix.php?id=55746&r=alreadyfixed
Need backtrace:  
https://bugs.php.net/fix.php?id=55746&r=needtrace
Need Reproduce Script:   
https://bugs.php.net/fix.php?id=55746&r=needscript
Try newer version:   
https://bugs.php.net/fix.php?id=55746&r=oldversion
Not developer issue: 
https://bugs.php.net/fix.php?id=55746&r=support
Expected behavior:   
https://bugs.php.net/fix.php?id=55746&r=notwrong
Not enough info: 
https://bugs.php.net/fix.php?id=55746&r=notenoughinfo
Submitted twice: 
https://bugs.php.net/fix.php?id=55746&r=submittedtwice
register_globals:
https://bugs.php.net/fix.php?id=55746&r=globals
PHP 4 support discontinued:  
https://bugs.php.net/fix.php?id=55746&r=php4
Daylight Savings:https://bugs.php.net/fix.php?id=55746&r=dst
IIS Stability:   
https://bugs.php.net/fix.php?id=55746&r=isapi
Install GNU Sed: 
https://bugs.php.net/fix.php?id=55746&r=gnused
Floating point limitations:  
https://bugs.php.net/fix.php?id=55746&r=float
No Zend Extensions:  
https://bugs.php.net/fix.php?id=55746&r=nozend
MySQL Configuration Error:   
https://bugs.php.net/fix.php?id=55746&r=mysqlcfg



Bug #55731 [Com]: __get after __unset

2011-09-21 Thread hytest at gmail dot com
Edit report at https://bugs.php.net/bug.php?id=55731&edit=1

 ID: 55731
 Comment by: hytest at gmail 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:

If we add following code:

echo $example->p3;  

It still just call __get once. Why it doesn't call it twice? 
( one for "p3" and one for "\0example\0p3" ? )

In another word: what's the different between a property not defined and a 
unset 
private property?


Previous Comments:

[2011-09-21 09:02:15] 421034509 at qq dot com

Thank you very much!You are so kind and patient!
I see your blog!
It's great!
您也是中国人吗?
我现在大四,现在在北京学习!刚接触php!希望以后还能请教您!


[2011-09-21 08:07:48] larue...@php.net

kind of right, you can refer to zend_std_read_property(in 
Zend/zend_object_handlers.c) for more details. 

and btw, you seems to be a chinese(using qq email), so if you are interesting 
of 
php internal, plz look at laruence.com, I will write these down in chinese in 
couple of days


[2011-09-21 07:42:19] 421034509 at qq dot com

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?


[2011-09-21 03:32:28] larue...@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?




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