Req->Bug #72635 [Opn->Ver]: ReflectionParameter::getDefaultValue() should not trigger fatal error
Edit report at https://bugs.php.net/bug.php?id=72635&edit=1
ID: 72635
Updated by: cmb@php.net
Reported by: david at grudl dot com
Summary: ReflectionParameter::getDefaultValue() should not
trigger fatal error
-Status: Open
+Status: Verified
-Type: Feature/Change Request
+Type: Bug
Package: Reflection related
PHP Version: 7.0.8
Block user comment: N
Private report: N
New Comment:
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>
Previous Comments:
------------------------------------------------------------------------
[2016-07-20 20:52:57] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72635&edit=1
Thread (4 messages)