From:             
Operating system: Linux
PHP version:      5.3.6
Package:          Variables related
Bug Type:         Bug
Bug description:Corrupted referenced strings inside Closure

Description:
------------
This is a bug in 5.3.6, which did not occur in 5.3.5. When executing a
Closure, 
and using a variable which references a string property of the context
class, the 
original string property becomes corrupted. Its first characters become
corrupted, 
resulting in an unexpected new string.
(Tested on several CentOS machines; 5.3.6 results in the bug, 5.3.5 does
not)

Step-by-step recreation: (code sample attached)
1. Define a string property in a class.
2. Define a Closure which accepts a parameter.
3. Execute that Closure, passing a parameter which is a reference to the
original 
string property.
4. The original string property becomes corrupted. If you var_dump() it,
you 
receive a corrupted string instead of your original string.

Test script:
---------------
class Foo
{
        public function __construct()
        {
                $this->a = 'foo';
        }
        public function bug()
        {
                $a = &$this->a;
                $b = function()use($a){
                        return strlen($a);
                };
                $b();
        }
}
 
$foo = new Foo();
$foo->bug();
var_dump($foo->a);

Expected result:
----------------
String(3) "foo"  (this happens in 5.3.5)


Actual result:
--------------
String(...) "{some_rubbish}oo"  (this happens in 5.3.6)

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

Reply via email to