Bug #78170 [Opn->Fbk]: Missing Z_PARAM_OPTIONAL results in a TypeError with incorrect message
| From: | kalle@php.net | Date: | Fri, 21 Jun 2019 15:11:38 +0000 |
| Subject: | Bug #78170 [Opn->Fbk]: 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-221437@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: kalle@php.net
Reported by: jasny@php.net
Summary: Missing Z_PARAM_OPTIONAL results in a TypeError with
incorrect message
-Status: Open
+Status: Feedback
Type: Bug
Package: Scripting Engine problem
PHP Version: 7.4Git-2019-06-14 (Git)
Block user comment: N
Private report: N
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