Bug #72594 [Opn->Ver]: Calling an earlier instance of an included anonymous class fatals with undefined method

From: Date: Thu, 14 Jul 2016 02:02:08 +0000
Subject: Bug #72594 [Opn->Ver]: Calling an earlier instance of an included anonymous class fatals with undefined method
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-202294@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72594&edit=1 ID: 72594 Updated by: requinix@php.net Reported by: php+bug at tubul dot net -Summary: Calling an earlier instance of an included anonymous class crashes +Summary: Calling an earlier instance of an included anonymous class fatals with undefined method -Status: Open +Status: Verified Type: Bug -Package: Scripting Engine problem +Package: Reproducible crash -Operating System: Linux +Operating System: Linux, Windows PHP Version: 7.0.8 Block user comment: N Private report: N New Comment: Self-contained version: https://3v4l.org/H4q8L get_object_vars($oldFoo) shows nothing and get_class_methods($oldFoo) shows "bar". Calling $oldFoo->bar() fatals trying to allocate random amounts of memory. Doing new ReflectionMethod($oldFoo,"bar") crashes. Does not happen if $bar is defined after bing(). Moving to Reproducible Crash since it's possible to get one. Previous Comments: ------------------------------------------------------------------------ [2016-07-14 01:17:00] php+bug at tubul dot net Description: ------------ 1) get an instance of an anonymous class returned from a included file 2) get another instance of the same class by including it again 3) have the second instance reference the first -> This gives a fatal error If in step 2) an exact copy of the file is included instead, the error doesn't happen. Leaving out the (never used) property of the class also prevents the error. PHP Version => 7.0.8 Configure Command => './configure' Server API => Command Line Interface Test script: --------------- <?php // test.php $oldFoo = require('foo.php'); $newFoo = require('foo.php'); // using a copy of foo.php here prevents the error $newFoo->bing($oldFoo); <?php // foo.php return new class{ public $bar; // comment out this line and there is no error public function bing($foo = null) { if ($foo) $foo->bing(); } }; Now run php test.php Expected result: ---------------- There should be no output Actual result: -------------- Fatal error: Uncaught Error: Call to undefined method class@anonymous::bing() in /home/richard/foo.php:6 Stack trace: #0 /home/richard/test.php(4): class@anonymous->bing(Object(class@anonymous)) #1 {main} thrown in /home/richard/foo.php on line 6 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=72594&edit=1

« previous php.bugs (#202294) next »