Bug #80815 [NEW]: opcache.preload duplicate definition with conditionally defined function
From: nicky dot demaeyer at gmail dot com
Operating system: linux
PHP version: 7.4.15
Package: opcache
Bug Type: Bug
Bug description:opcache.preload duplicate definition with conditionally defined function
Description:
------------
When a function is defined inside an if/else block it will produce a
Cannot redeclare error when the function is loaded in
opcache.preload.
removing the if statement solves the error.
The documentation states:
https://www.php.net/manual/en/opcache.preloading.php:
> include will execute code in the file, while opcache_compile_file()
will not. That means only the former supports conditional declaration
(functions declared inside an if-block).
Test script:
---------------
<?php #function.php
if (false) {
function myFunction() {}
} else {
function myFunction() {}
}
<?php #preload.php
include __DIR__ . "/function.php";
<?php #index.php
require __DIR__ . "/function.php";
Running this in the dev server will produce the error:
php -d opcache.preload=preload.php -S localhost:8080
Actual result:
--------------
Fatal error: Cannot redeclare myFunction() (previously declared in
/app/function.php:6) in /app/function.php on line 6
--
Edit bug report at https://bugs.php.net/bug.php?id=80815&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80815&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80815&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80815&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80815&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80815&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80815&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80815&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80815&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80815&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80815&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80815&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80815&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80815&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80815&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80815&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80815&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80815&r=mysqlcfg
Thread (4 messages)
- nicky dot demaeyer at gmail dot com