php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78170 Missing Z_PARAM_OPTIONAL results in a TypeError with incorrect message
Submitted: 2019-06-14 22:06 UTC Modified: 2019-06-30 04:22 UTC
From: jasny@php.net Assigned:
Status: No Feedback Package: Scripting Engine problem
PHP Version: 7.4Git-2019-06-14 (Git) OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2019-06-14 22:06 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-06-14 22:20 UTC] 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-21 15:11 UTC] kalle@php.net
-Status: Open +Status: Feedback
 [2019-06-30 04:22 UTC] php-bugs at lists dot php dot net
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.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri Dec 02 03:05:53 2022 UTC