Bug #55349 [Opn->Csd]: Corrupted referenced strings inside Closure
Edit report at https://bugs.php.net/bug.php?id=55349&edit=1
ID: 55349
Updated by: felipe@php.net
Reported by: roeitell at gmail dot com
Summary: Corrupted referenced strings inside Closure
-Status: Open
+Status: Closed
Type: Bug
-Package: Variables related
+Package: Scripting Engine problem
Operating System: Linux
PHP Version: 5.3.6
-Assigned To:
+Assigned To: felipe
Block user comment: N
Private report: N
New Comment:
This bugs already has been fixed. Thanks.
Previous Comments:
------------------------------------------------------------------------
[2011-08-02 16:09:49] 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)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=55349&edit=1
Thread (2 messages)