function foo($opts) {
echo $opts['source'] . $opts['destination'];
}
// just one extra pair of [] needed instead of new array()
foo(['source' => '/123', 'destination' => '/abc']); function foo($opts) {
echo $opts['source'] . $opts['destination'];
}
// just one extra pair of [] needed instead of new array()
foo(['source' => '/123', 'destination' => '/abc']);Unless you've ever used languages with actual first-class keyword arguments (Python) and languages using hashes as pseudo-kwargs (Ruby, JavaScript). Then you know it's no substitute.
Also, you could already do just that in PHP before, it simply took 5 more characters.
For example, fgetcsv takes parameters for delimiter, enclosure, and escape char (as of 5.3). Right now, if I want to specify a different enclosure, I'm forced to specify a delimiter even if I still want to use the default. I'd much prefer the ability to tell the function call that I want to override the enclosure and leave the delimiter alone.
Absolutely. But PHP devs have repeatedly refused to support named parameters so this is a good enough fix.
The story of PHP's life.
foo(array('source' => '/123', 'destination' => '/abc'));
Short syntax will make it less repetitive though. You can also use something like array_merge to emulate jQuery's $.extend for creating defaults.