[php-src] Issue #11975: Anonymous class names change based on the opcache status of the PHP file

From: Date: Mon, 14 Aug 2023 23:23:23 +0000
Subject: [php-src] Issue #11975: Anonymous class names change based on the opcache status of the PHP file
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-245186@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/11975 Author: nunomaduro ### Description It seems that anonymous class names change based on the opcache status of the PHP file that includes the anonymous class declaration. Here is an example: ```php <?php // A.php var_dump(get_class(require 'B.php')); var_dump(get_class(require 'B.php')); var_dump(get_class(require 'B.php')); var_dump(get_class(require 'B.php')); <?php // B.php return new class {}; ``` Resulted in this output: ``` # First Scenario "Without opcache": ➜ php -d "opcache.enable_cli"=0 A.php /Users/nunomaduro/demo/A.php:3: string(48) "class@anonymous\000/Users/nunomaduro/demo/B.php:3$5" /Users/nunomaduro/demo/A.php:4: string(48) "class@anonymous\000/Users/nunomaduro/demo/B.php:3$6" /Users/nunomaduro/demo/A.php:5: string(48) "class@anonymous\000/Users/nunomaduro/demo/B.php:3$7" /Users/nunomaduro/demo/A.php:6: string(48) "class@anonymous\000/Users/nunomaduro/demo/B.php:3$8" ``` ``` # Second Scenario "With opcache" (and after running the script once, so the file gets cached) ➜ php -d "opcache.enable_cli"=1 A.php /Users/nunomaduro/demo/A.php:3: string(48) "class@anonymous\000/Users/nunomaduro/demo/B.php:3$5" /Users/nunomaduro/demo/A.php:4: string(48) "class@anonymous\000/Users/nunomaduro/demo/B.php:3$5" /Users/nunomaduro/demo/A.php:5: string(48) "class@anonymous\000/Users/nunomaduro/demo/B.php:3$5" /Users/nunomaduro/demo/A.php:6: string(48) "class@anonymous\000/Users/nunomaduro/demo/B.php:3$5" ``` It's unclear to me whether the "expected" output should correspond to the first or the second scenario. However, the fact that the generated class names vary depending on the opcache status of the file is what prompted me to create the issue. ### PHP Version PHP 8.2.8 ### Operating System _No response_

« previous php.bugs (#245186) next »