Req #70231 [NEW]: Ability to set default params within a functions arguments as an array/object
From: mintystark at gmail dot com
Operating system: Ubuntu
PHP version: 7.0.0beta3
Package: Arrays related
Bug Type: Feature/Change Request
Bug description:Ability to set default params within a functions arguments as an array/object
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' => '');
--
Edit bug report at https://bugs.php.net/bug.php?id=70231&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70231&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70231&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70231&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=70231&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=70231&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=70231&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=70231&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=70231&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=70231&r=support
Expected behavior: https://bugs.php.net/fix.php?id=70231&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=70231&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=70231&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=70231&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70231&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=70231&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=70231&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=70231&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70231&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=70231&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=70231&r=mysqlcfg
Thread (3 messages)
- mintystark at gmail dot com