|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77644 [preload] Uncaught Error: Undefined constant
Submitted: 2019-02-21 01:44 UTC Modified: 2019-02-25 20:02 UTC
From: mberchtold at gmail dot com Assigned: dmitry (profile)
Status: Not a bug Package: opcache
PHP Version: master-Git-2019-02-21 (snap) OS: Windows 10 x64
Private report: No CVE-ID: None
 [2019-02-21 01:44 UTC] mberchtold at gmail dot com
When a class that uses a constant with a namespace prefix is preloaded, using the class results in a fatal error.

Test script:


namespace mytest;

define(__NAMESPACE__ . '\CONSTANTINE', 'value');

class Test
	public function __construct()

new \mytest\Test();

Expected result:
no error

Actual result:
PHP Fatal error:  Uncaught Error: Undefined constant 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-02-21 08:39 UTC]
-Summary: PHP Fatal error: Uncaught Error: Undefined constant +Summary: [preload] Uncaught Error: Undefined constant
 [2019-02-21 09:08 UTC]
-Assigned To: +Assigned To: dmitry
 [2019-02-21 09:08 UTC]
I believe that constants are not preloaded intentionally. @dmitry: Can you explain why constants cannot be preloaded?
 [2019-02-22 11:57 UTC]
-Status: Assigned +Status: Not a bug
 [2019-02-22 11:57 UTC]
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.


For now, I mark this as "Not a bug".
 [2019-02-22 15:36 UTC] 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 17:34 UTC] mberchtold at gmail dot com
Maybe you could prevent preloading of classes with undefined constants?
 [2019-02-25 20:02 UTC]
The class "Test" is preloaded, but the script still has to be included or required (it's cached by opcache).

new \mytest\Test();
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Sep 25 04:01:25 2023 UTC