php.net |  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
Votes:13
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
 [2016-07-20 20:52 UTC] david at grudl dot com
Description:
------------
ReflectionParameter::getDefaultValue() should not trigger uncatchable (not even in PHP 7) fatal error, when constant is undefined. It should throw ReflectionException or Error.

Test: https://3v4l.org/X8gXu and https://3v4l.org/EEQFI

Test script:
---------------
<?php

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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-09-05 17:43 UTC] cmb@php.net
-Status: Open +Status: Verified -Type: Feature/Change Request +Type: Bug
 [2018-09-05 17:43 UTC] cmb@php.net
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] <https://3v4l.org/hAdkZ>
[2] <https://3v4l.org/X1YVX>
[3] <https://github.com/php/php-src/blob/php-7.3.0beta3/Zend/zend_execute_API.c#L559>
 [2018-09-29 12:20 UTC] nikic@php.net
-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] nikic@php.net
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=8b8b625d088c859a3dc42f31acd7ec95b780158e
Log: Fixed bug #72635
 [2018-09-29 12:23 UTC] nikic@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 17:01:29 2024 UTC