Bug #77652 [Opn->Asn]: Anonymous classes can lose their interface information

From: Date: Fri, 22 Feb 2019 08:47:22 +0000
Subject: Bug #77652 [Opn->Asn]: Anonymous classes can lose their interface information
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-219695@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77652&edit=1 ID: 77652 Updated by: nikic@php.net Reported by: eric at ericstern dot com Summary: Anonymous classes can lose their interface information -Status: Open +Status: Assigned Type: Bug Package: Scripting Engine problem Operating System: macOS 10.14 PHP Version: 7.3.2 -Assigned To: +Assigned To: nikic Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [2019-02-22 04:16:24] eric at ericstern dot com I could reproduce it in the official docker image (php:7.3.2-cli) which does not have opcache installed. So yes, I suppose so. ------------------------------------------------------------------------ [2019-02-22 04:13:40] requinix@php.net Does it work if you disable opcache? ------------------------------------------------------------------------ [2019-02-22 04:04:06] eric at ericstern dot com 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 this bug report at https://bugs.php.net/bug.php?id=77652&edit=1

« previous php.bugs (#219695) next »