Req #81595 [Com]: Arguments count should be checked prior individual argument type

From: Date: Wed, 21 Jun 2023 09:51:19 +0000
Subject: Req #81595 [Com]: Arguments count should be checked prior individual argument type
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-244765@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81595&edit=1 ID: 81595 Comment by: phamdinhkhangu315 at gmail dot com Reported by: michael dot vorisek at email dot cz Summary: Arguments count should be checked prior individual argument type Status: Open Type: Feature/Change Request Package: *General Issues Operating System: any PHP Version: 7.4.25 Block user comment: N Private report: N New Comment: Argument count validation: Verifying the count of arguments before checking their types can help ensure that the correct number of arguments are provided. This can be particularly useful when a specific number of arguments is expected, such as when invoking a function with a fixed parameter list. By checking the count first, you can provide more informative error messages to users if they pass an incorrect number of arguments. Early error detection: If the count of arguments is incorrect, it may be unnecessary to proceed with checking individual argument types. By catching this error early, you can avoid potentially unnecessary computational or validation steps. This can improve efficiency, especially if the type checking process is resource-intensive. (https://www.targetpayandbenefits.us/)github.com Previous Comments: ------------------------------------------------------------------------ [2021-11-08 09:03:23] nikic@php.net Why is this order better? ------------------------------------------------------------------------ [2021-11-06 14:15:06] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=81595&edit=1

« previous php.bugs (#244765) next »