php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55349 Corrupted referenced strings inside Closure
Submitted: 2011-08-02 16:09 UTC Modified: 2011-11-15 20:11 UTC
From: roeitell at gmail dot com Assigned: felipe (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3.6 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: roeitell at gmail dot com
New email:
PHP Version: OS:

 

 [2011-08-02 16:09 UTC] roeitell at gmail dot com
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)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-11-15 20:11 UTC] felipe@php.net
-Status: Open +Status: Closed -Package: Variables related +Package: Scripting Engine problem -Assigned To: +Assigned To: felipe
 [2011-11-15 20:11 UTC] felipe@php.net
This bugs already has been fixed. Thanks.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 20 21:00:02 2025 UTC