|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-08-26 17:19 UTC] jhdxr@php.net
[2015-10-19 22:28 UTC] rahi at atsspec dot co
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 19:00:01 2025 UTC |
Description: ------------ Currently if you want to send an array of parameters to a function, but have the function also use defaults in the array you then need to use array_merge in the function. It would be useful if the function arguments could handle this automatically. As far as the syntax goes I don't care, but I would really like this as it would reduce the amount of code I need to write and it would make it more readable. Plus allow for phpDocumentor and other features to utilize this. Also I am sure you can make this more compatible with the compiler thus ran faster then using other methods like array_merge() etc. Suggested Syntax Options: function do_stuff($arr = {'a' => 'blue', 'b' => 'red', 'c' => 'black', 'd' => 'yellow'}) function do_stuff($arr = ['a' => 'blue', 'b' => 'red', 'c' => 'black', 'd' => 'yellow']) function do_stuff($arr = &array('a' => 'blue', 'b' => 'red', 'c' => 'black', 'd' => 'yellow')) Example Shown in the Test Script Below. Test script: --------------- function do_stuff($arr = {'a' => 'blue', 'b' => 'red', 'c' => 'black', 'd' => 'yellow'}) { return $arr; } print_r(do_stuff(array('b' => 'green', 'c' => null, 'd' => '')); Expected result: ---------------- // Should output // Array('a' => 'blue', 'b' => 'green', 'c' => 'black', 'd' => ''); // OR // Object('a' => 'blue', 'b' => 'green', 'c' => 'black', 'd' => '');