From:             foddex at foddex dot net
Operating system: Linux Fedora 9
PHP version:      5.2.8
PHP Bug Type:     Unknown/Other Function
Bug description:  Type of variable changes after it has been returned by 
reference

Description:
------------
When a class member variable gets returned by reference, the member
variable itself turns into a reference. See the URL below for more detailed
information (it contains a lot of comments).

The basic idea is:
class A { 
  var $foo; 
  function &get() { return $this->foo; }
}

If we clone an instance of A when get() hasn't been returned yet, the
value of $foo gets cloned. If we call get(), and then clone the instance of
A, the cloned object references the same data as the original! This might
be logical because it had become a reference, but this behavior is not
documented and thus pretty unexpected, IMHO.

Reproduce code:
---------------
http://pastebin.be/16008

Expected result:
----------------
object(A)#1 (1) {
  ["foo"]=>
  int(42)
}
int(42)
int(43)
int(42)
object(A)#1 (1) {
  ["foo"]=>
  int(43)
}


Actual result:
--------------
object(A)#1 (1) {
  ["foo"]=>
  int(42)
}
int(42)
int(43)
int(43)
object(A)#1 (1) {
  ["foo"]=>
  &int(43)
}


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

Reply via email to