Bug #80815 [Com]: opcache.preload duplicate definition with conditionally defined function

From: Date: Mon, 01 Mar 2021 11:15:48 +0000
Subject: Bug #80815 [Com]: opcache.preload duplicate definition with conditionally defined function
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-232444@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80815&edit=1 ID: 80815 Comment by: nicky dot demaeyer at gmail dot com Reported by: nicky dot demaeyer at gmail dot com Summary: opcache.preload duplicate definition with conditionally defined function Status: Open Type: Bug Package: opcache Operating System: linux PHP Version: 7.4.15 Block user comment: N Private report: N New Comment: also tested this on PHP 8.0.1 with the same result. Previous Comments: ------------------------------------------------------------------------ [2021-03-01 11:10:44] nicky dot demaeyer at gmail dot com 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 this bug report at https://bugs.php.net/bug.php?id=80815&edit=1

« previous php.bugs (#232444) next »