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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jasny@php.net
New email:
PHP Version: OS:

 

 [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-2024 The PHP Group
All rights reserved.
Last updated: Sun May 26 19:01:30 2024 UTC