php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72014 Including a file with anonymous classes multiple times leads to fatal error
Submitted: 2016-04-13 09:54 UTC Modified: -
From: gabriel dot birke at gmail dot com Assigned:
Status: Closed Package: opcache
PHP Version: 7.0.5 OS: Linux
Private report: No CVE-ID: None
 [2016-04-13 09:54 UTC] gabriel dot birke at gmail dot com
Description:
------------
When opcache is enabled, including a file with an anonymous class multiple times causes the error message "Cannot declare class class@anonymous, because the name is already in use". When turning off opcache in the php.ini (setting opcache.enabled=0) the error message disappears.

Test script:
---------------
<?php
/** file anon.php */
$a = new class() { public $testvar = "Foo\n"; };
echo $a->testvar;

?>

<?php
/** file inlcude_test.php */
include("anon.php");
include("anon.php");

Expected result:
----------------
Foo
Foo


Actual result:
--------------
Foo
PHP Fatal error:  Cannot declare class class@anonymous, because the name is already in use in /var/www/anon.php on line 3

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-04-14 12:21 UTC] laruence@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=8a17b1a2415cc3a44b74bb9bab18d6dded1ee9b0
Log: Fixed bug #72014 (Including a file with anonymous classes multiple times leads to fatal error)
 [2016-04-14 12:21 UTC] laruence@php.net
-Status: Open +Status: Closed
 [2016-07-20 11:32 UTC] davey@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=8a17b1a2415cc3a44b74bb9bab18d6dded1ee9b0
Log: Fixed bug #72014 (Including a file with anonymous classes multiple times leads to fatal error)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 08:01:29 2024 UTC