note 129796 added to functions.arguments

From: Date: Tue, 08 Oct 2024 00:54:35 +0000
Subject: note 129796 added to functions.arguments
Groups: php.notes 
Request: Send a blank email to php-notes+get-221583@lists.php.net to get a copy of this message
When using variable-length argument lists (varargs) and named arguments, it may break your code in some use cases. The code is in here: https://3v4l.org/qFEf7 ``` function numbers($first, $second, ...$third) { var_dump($first, $second, $third); echo '---------------' . PHP_EOL; } numbers(1, 2, [3, 4]); numbers(1, 2, numbers: [2, 3, 4]); numbers(second: 2, first: 1, third: [2, 3, 4]); ``` Firstly, if someone doesn't use the named argument, it's an array using the integer index. But when someone uses the named parameter, the array key becomes the parameter name. And it doesn't even require to match the name of the parameter. It can be anything. ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.5.137 (proxied: 103.51.53.37) ---- Manual Page -- https://php.net/manual/en/functions.arguments.php Edit -- https://main.php.net/note/edit/129796 Del: integrated -- https://main.php.net/note/delete/129796/integrated Del: useless -- https://main.php.net/note/delete/129796/useless Del: bad code -- https://main.php.net/note/delete/129796/bad+code Del: spam -- https://main.php.net/note/delete/129796/spam Del: non-english -- https://main.php.net/note/delete/129796/non-english Del: in docs -- https://main.php.net/note/delete/129796/in+docs Del: other reasons-- https://main.php.net/note/delete/129796 Reject -- https://main.php.net/note/reject/129796 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#221583) next »