|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72635 Undefined class used by class constant in constexpr generates fatal error
Submitted: 2016-07-20 20:52 UTC Modified: 2018-09-29 12:20 UTC
Avg. Score:4.3 ± 0.9
Reproduced:12 of 12 (100.0%)
Same Version:11 (91.7%)
Same OS:6 (50.0%)
From: david at grudl dot com Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 7.0.8 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: david at grudl dot com
New email:
PHP Version: OS:


 [2016-07-20 20:52 UTC] david at grudl dot com
ReflectionParameter::getDefaultValue() should not trigger uncatchable (not even in PHP 7) fatal error, when constant is undefined. It should throw ReflectionException or Error.

Test: and

Test script:

class Test
    function method($a = self::UNDEFINED) // or UndefinedClass::UNDEFINED

$rp = new ReflectionParameter(['Test', 'method'], 'a');
$val = $rp->getDefaultValue();

Expected result:
ReflectionException or Error in PHP 7

Actual result:
Fatal Error


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-09-05 17:43 UTC]
-Status: Open +Status: Verified -Type: Feature/Change Request +Type: Bug
 [2018-09-05 17:43 UTC]
In the first case (self::UNDEFINED) PHP 7 actually throws an Error
exception[1].  A ReflectionException appears to be more
appropriate, but that's not a big issue.

In the second case (UndefinedClass::UNDEFINED) PHP issues a fatal
error[2].  Given that `new ReflectionClass('UndefinedClass)` would
throw a ReflectionException, I rather consider the current
behavior to be a bug.

To avoid the fatal error zend_get_constant_ex() would have to be
called[3] with the ZEND_FETCH_CLASS_SILENT flag, but that seems
hard to accomplish.

[1] <>
[2] <>
[3] <>
 [2018-09-29 12:20 UTC]
-Summary: ReflectionParameter::getDefaultValue() should not trigger fatal error +Summary: Undefined class used by class constant in constexpr generates fatal error -Status: Verified +Status: Assigned -Package: Reflection related +Package: Scripting Engine problem -Assigned To: +Assigned To: nikic
 [2018-09-29 12:23 UTC]
Automatic comment on behalf of
Log: Fixed bug #72635
 [2018-09-29 12:23 UTC]
-Status: Assigned +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 01 12:01:29 2024 UTC