php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #81595 Arguments count should be checked prior individual argument type
Submitted: 2021-11-06 14:15 UTC Modified: 2021-11-08 09:03 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: michael dot vorisek at email dot cz Assigned:
Status: Open Package: *General Issues
PHP Version: 7.4.25 OS: any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: michael dot vorisek at email dot cz
New email:
PHP Version: OS:

 

 [2021-11-06 14:15 UTC] michael dot vorisek at email dot cz
Description:
------------
If arguments count does not match, it should be reported instead of trying to check the arguments type first.

https://3v4l.org/X53qH

Test script:
---------------
function test(int $a, string $b) {
}

try {
    test(1);
} catch (Error $e) { echo $e->getMessage() . "\n"; }

try {
    test('test');
} catch (Error $e) { echo $e->getMessage() . "\n"; }

Expected result:
----------------
Too few arguments to function test(), 1 passed in /in/X53qH on line 7 and exactly 2 expected
Too few arguments to function test(), 1 passed in /in/X53qH on line 7 and exactly 2 expected

Actual result:
--------------
Too few arguments to function test(), 1 passed in /in/X53qH on line 7 and exactly 2 expected
test(): Argument #1 ($a) must be of type int, string given, called in /in/X53qH on line 11

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-11-08 09:03 UTC] nikic@php.net
Why is this order better?
 [2023-07-31 09:40 UTC] LizethBethtzs87 at gmail dot com
Hello,

Prior to checking individual argument types, it is crucial to verify the count of arguments. This ensures that the correct number of arguments has been provided, avoiding potential errors due to missing or excessive inputs. By validating the argument count first, developers can prevent unnecessary evaluations of argument types and improve code efficiency. This practice enhances code reliability, reduces debugging efforts, and promotes a cleaner programming approach. In summary, counting arguments before examining their types lays a strong foundation for robust and error-free code execution.
(https://github.com.php)(https://www.surveyzo.com/cafe-rio-listens/)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 16:01:29 2024 UTC