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

From: Date: Mon, 31 Jul 2023 09:40:22 +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-245072@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: LizethBethtzs87 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: 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/) 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 (#245072) next »