Bug #77050 [Opn->Dup]: eval and new anonymous class bug
| From: | cmb@php.net | Date: | Tue, 23 Oct 2018 09:21:24 +0000 |
| Subject: | Bug #77050 [Opn->Dup]: eval and new anonymous class bug | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-217661@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77050&edit=1
ID: 77050
Updated by: cmb@php.net
Reported by: admin at yurunsoft dot com
Summary: eval and new anonymous class bug
-Status: Open
+Status: Duplicate
Type: Bug
-Package: *General Issues
+Package: Scripting Engine problem
Operating System: All
PHP Version: 7.1.23
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Duplicate of bug #73816.
Previous Comments:
------------------------------------------------------------------------
[2018-10-23 04:29:13] a at b dot c dot de
Shorter test case:
<?php
class A{}
class B{}
for($i = 0; $i < 10; ++$i)
{
$c = ['A','B'][rand() % 2];
$t = eval("return new class extends $c{};");
echo get_parent_class($t);
}
?>
It doesn't happen when the loop is unrolled:
<?php
$c = ['A','B'][rand() % 2];
$t = eval("return new class extends $c{};");
echo get_parent_class($t);
$c = ['A','B'][rand() % 2];
$t = eval("return new class extends $c{};");
echo get_parent_class($t);
....
?>
But it does happen if the eval is then wrapped in a function:
<?php
function make($c)
{
return eval("return new class extends $c{};");
}
$c = ['A','B'][rand() % 2];
$t = make($c);
echo get_parent_class($t);
$c = ['A','B'][rand() % 2];
$t = make($c);
echo get_parent_class($t);
....
?>
Two identical make() functions:
<?php
class A{}
class B{}
function make1($c)
{
return eval("return new class extends $c{};");
}
function make2($c)
{
return eval("return new class extends $c{};");
}
echo get_parent_class(make1('A')); // Outputs A as expected
echo get_parent_class(make2('B')); // Outputs B as expected
echo get_parent_class(make1('B')); // Outputs A instead of B
echo get_parent_class(make2('A')); // Outputs B instead of A
?>
------------------------------------------------------------------------
[2018-10-23 01:51:06] admin at yurunsoft dot com
Description:
------------
eval and new anonymous class, always return the first result
Test script:
---------------
https://gist.github.com/Yurunsoft/f80b6e234a031cdd320d28bb629947a3
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77050&edit=1