php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72594 Calling an earlier instance of an included anonymous class fatals
Submitted: 2016-07-14 01:17 UTC Modified: 2016-07-14 02:02 UTC
From: php+bug at tubul dot net Assigned:
Status: Closed Package: Reproducible crash
PHP Version: 7.0.8 OS: Linux, Windows
Private report: No CVE-ID: None
 [2016-07-14 01:17 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-07-14 02:02 UTC] requinix@php.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 -Package: Scripting Engine problem +Package: Reproducible crash -Operating System: Linux +Operating System: Linux, Windows
 [2016-07-14 02:02 UTC] requinix@php.net
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.
 [2016-07-14 02:02 UTC] requinix@php.net
-Summary: Calling an earlier instance of an included anonymous class fatals with undefined +Summary: Calling an earlier instance of an included anonymous class fatals
 [2016-07-14 05:38 UTC] laruence@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=8c5b27e0617bf0899d7e830ed3029711125a0ddb
Log: Fixed bug #72594 (Calling an earlier instance of an included anonymous class fatals)
 [2016-07-14 05:38 UTC] laruence@php.net
-Status: Verified +Status: Closed
 [2016-07-20 11:29 UTC] davey@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=8c5b27e0617bf0899d7e830ed3029711125a0ddb
Log: Fixed bug #72594 (Calling an earlier instance of an included anonymous class fatals)
 [2016-10-17 10:11 UTC] bwoebi@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=8c5b27e0617bf0899d7e830ed3029711125a0ddb
Log: Fixed bug #72594 (Calling an earlier instance of an included anonymous class fatals)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 13:01:28 2024 UTC