|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 12:00:01 2025 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] <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>