Bug #72635 [Ver->Asn]: Undefined class used by class constant in constexpr generates fatal error

From: Date: Sat, 29 Sep 2018 12:20:24 +0000
Subject: Bug #72635 [Ver->Asn]: Undefined class used by class constant in constexpr generates fatal error
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-217278@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72635&edit=1 ID: 72635 Updated by: nikic@php.net Reported by: david at grudl dot com -Summary: ReflectionParameter::getDefaultValue() should not trigger fatal error +Summary: Undefined class used by class constant in constexpr generates fatal error -Status: Verified +Status: Assigned Type: Bug -Package: Reflection related +Package: Scripting Engine problem PHP Version: 7.0.8 -Assigned To: +Assigned To: nikic Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [2018-09-05 17:43:58] 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> ------------------------------------------------------------------------ [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

« previous php.bugs (#217278) next »