Bug #77644 [Nab]: [preload] Uncaught Error: Undefined constant

From: Date: Mon, 25 Feb 2019 20:02:00 +0000
Subject: Bug #77644 [Nab]: [preload] Uncaught Error: Undefined constant
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-219731@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77644&edit=1 ID: 77644 Updated by: dmitry@php.net Reported by: mberchtold at gmail dot com Summary: [preload] Uncaught Error: Undefined constant Status: Not a bug Type: Bug Package: opcache Operating System: Windows 10 x64 PHP Version: master-Git-2019-02-21 (snap) Assigned To: dmitry Block user comment: N Private report: N New Comment: The class "Test" is preloaded, but the script still has to be included or required (it's cached by opcache). <?php include("preload_undef_const_4.inc"); new \mytest\Test(); Previous Comments: ------------------------------------------------------------------------ [2019-02-22 17:34:22] mberchtold at gmail dot com Maybe you could prevent preloading of classes with undefined constants? ------------------------------------------------------------------------ [2019-02-22 15:36:43] mberchtold at gmail dot com It fails at runtime and not during preloading. I dont see how this is not a bug. ------------------------------------------------------------------------ [2019-02-22 11:57:13] dmitry@php.net Preloading works only with functions and classes (not with whole scripts). Constants in PHP always handled at run-time. define() is a function that side effect can't be cached, because of possible re-defintion. See https://wiki.php.net/rfc/constant_redefinition For now, I mark this as "Not a bug". ------------------------------------------------------------------------ [2019-02-21 09:08:47] nikic@php.net I believe that constants are not preloaded intentionally. @dmitry: Can you explain why constants cannot be preloaded? ------------------------------------------------------------------------ [2019-02-21 01:44:02] mberchtold at gmail dot com Description: ------------ When a class that uses a constant with a namespace prefix is preloaded, using the class results in a fatal error. Test script: --------------- --INI-- opcache.enable=1 opcache.enable_cli=1 opcache.optimization_level=-1 opcache.preload={PWD}/preload_undef_const_4.inc preload_undef_const_4.inc: <?php namespace mytest; define(__NAMESPACE__ . '\CONSTANTINE', 'value'); class Test { public function __construct() { echo CONSTANTINE; } } --FILE-- <?php new \mytest\Test(); Expected result: ---------------- no error Actual result: -------------- PHP Fatal error: Uncaught Error: Undefined constant ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=77644&edit=1

« previous php.bugs (#219731) next »