Bug #77652 [NEW]: Anonymous classes can lose their interface information
| From: | eric at ericstern dot com | Date: | Fri, 22 Feb 2019 04:04:06 +0000 |
| Subject: | Bug #77652 [NEW]: Anonymous classes can lose their interface information | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-219689@lists.php.net to get a copy of this message | ||
From: eric at ericstern dot com
Operating system: macOS 10.14
PHP version: 7.3.2
Package: Scripting Engine problem
Bug Type: Bug
Bug description:Anonymous classes can lose their interface information
Description:
------------
When a closure returns an anonymous class that implements an interface
is returned in a file that is require()d multiple times, subsequent
return values have the interface information stripped.
I discovered this behavior while writing unit tests around a
configuration tool (asserting that the returned value implemented an
interface) - the test would pass if it was the _first_ test to run, but
fail otherwise. It would also pass if I ran the tests with process
isolation enabled. The attached script is the simplest reproduce case I
could come up with.
Test script:
---------------
// run.php
<?php
interface I {}
require 'data.php'; // comment this line out to get the expected
behavior
$data = require 'data.php';
print_r(class_implements($data['I']()));
// data.php
<?php
return [
'I' => function() {
return new class implements I {};
},
];
Expected result:
----------------
$ php run.php
Array
(
[I] => I
)
Actual result:
--------------
$ php run.php
Array
(
)
--
Edit bug report at https://bugs.php.net/bug.php?id=77652&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77652&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77652&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77652&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=77652&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=77652&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=77652&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=77652&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=77652&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=77652&r=support
Expected behavior: https://bugs.php.net/fix.php?id=77652&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=77652&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=77652&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=77652&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77652&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=77652&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=77652&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=77652&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77652&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=77652&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=77652&r=mysqlcfg