Bug #78170 [Fbk->NoF]: Missing Z_PARAM_OPTIONAL results in a TypeError with incorrect message

From: Date: Sun, 30 Jun 2019 04:22:05 +0000
Subject: Bug #78170 [Fbk->NoF]: Missing Z_PARAM_OPTIONAL results in a TypeError with incorrect message
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-221565@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78170&edit=1 ID: 78170 Updated by: php-bugs@lists.php.net Reported by: jasny@php.net Summary: Missing Z_PARAM_OPTIONAL results in a TypeError with incorrect message -Status: Feedback +Status: No Feedback Type: Bug Package: Scripting Engine problem PHP Version: 7.4Git-2019-06-14 (Git) Private report: N New Comment: No feedback was provided. The bug is being suspended because we assume that you are no longer experiencing the problem. If this is not the case and you are able to provide the information that was requested earlier, please do so and change the status of the bug back to "Re-Opened". Thank you. Previous Comments: ------------------------------------------------------------------------ [2019-06-14 22:20:25] nikic@php.net Are you using a debug build? There are assertions that are supposed to catch this: https://github.com/php/php-src/blob/master/Zend/zend_API.h#L1192 ------------------------------------------------------------------------ [2019-06-14 22:06:29] jasny@php.net Description: ------------ When a function has optional parameters, the use of Z_PARAM_OPTIONAL is required. Forgetting to add this macro leads to a TypeError with a message about the given required argument instead of the missing argument. Test script: --------------- PHP_FUNCTION(test_it) { zend_long code; char *phrase; size_t phrase_len; ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 1, 2) Z_PARAM_LONG(code) Z_PARAM_STRING(phrase, phrase_len) ZEND_PARSE_PARAMETERS_END_EX(); //... } <?php test_it(100); ?> Expected result: ---------------- Fatal error: Uncaught TypeError: test_it() expects parameter 2 to be string, null given Actual result: -------------- Fatal error: Uncaught TypeError: test_it() expects parameter 1 to be integer, integer given ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=78170&edit=1

« previous php.bugs (#221565) next »