|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51791 constant() aborts execution when fail to check undefined constant
Submitted: 2010-05-11 12:12 UTC Modified: 2010-05-17 13:05 UTC
From: iliavlad at mail dot ru Assigned: felipe
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3.2 OS: Windows, Linux
Private report: No CVE-ID:
 [2010-05-11 12:12 UTC] iliavlad at mail dot ru
constant() failed to check undefined constant and php interpreter stoped, but constant() should return NULL and php interpreter should continue to work.

Test script:
class A 
    const B = 1;
echo 5;

Expected result:
Warning: constant(): Couldn't find constant A::B1

Actual result:
>php -v 
PHP 5.3.2 (cli) (built: Mar 3 2010 19:40:13) 
Copyright (c) 1997-2010 The PHP Group 
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies 

>php -r "class A { const B = 1;} var_dump(@constant('A::B1')); echo 5;" 

>php -r "class A { const B = 1;} var_dump(constant('A::B1')); echo 5;" 

Fatal error: Undefined class constant 'A::B1' in Command line code on line 1 

Call Stack: 
0.0003 317608 1. {main}() Command line code:0 
0.0003 317688 2. constant() Command line code:1


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-12 08:16 UTC]
-Status: Open +Status: Bogus
 [2010-05-12 08:16 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

 [2010-05-13 00:09 UTC] iliavlad at mail dot ru
Hi Mike,

according to manual constant() eturns the value of the constant, or NULL if the constant is not defined. And this happens with php 5.2 version. With php 5.3 there is a fatal error and php interpreter stops. There are no words about fatal error in manual.
 [2010-05-13 01:02 UTC]
-Status: Bogus +Status: Open
 [2010-05-13 01:02 UTC]
I don't see this change mentioned at any of the following locations:

Therefore, it can't be completely bogus. Please explain if this BC break in 5_3 
is intentional. constant('IDONOTEXIST') still returns NULL however, with 
E_WARNING instead of E_FATAL.
 [2010-05-13 03:16 UTC]
-Status: Open +Status: Verified -Package: Reproducible crash +Package: Scripting Engine problem
 [2010-05-13 03:16 UTC]
This is definitely a bug.
 [2010-05-13 04:12 UTC]
-Summary: constant() failed to check undefined constant and php interpreter stoped +Summary: constant() aborts execution when fail to check undefined constant
 [2010-05-13 04:13 UTC]
Automatic comment from SVN on behalf of felipe
Log: - Fixed bug #51791 (constant() aborts execution when fail to check undefined constant)
 [2010-05-13 04:13 UTC]
-Status: Verified +Status: Closed -Assigned To: +Assigned To: felipe
 [2010-05-13 04:13 UTC]
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

 [2010-05-17 08:12 UTC]
How's this a bug?

 [2010-05-17 13:04 UTC]
constant('not::exists') was issuing an E_FATAL.
 [2010-05-17 13:05 UTC]
Oops, s/E_FATAL/E_ERROR/ :)
PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 16:01:42 2015 UTC