3 ms·
can you not already pass in a named array ? function stuff($a, $b, $sep = null, $clean = null) { // wooop } $params = array('a' => 1, 'b' => 2, 'clean' =>
by AlexC04 16y ago
can you not already pass in a named array ?
function stuff($a, $b, $sep = null, $clean = null) {
// wooop
}
$params = array('a' => 1, 'b' => 2, 'clean' => true);
stuff($params);
I've never actually played with that directly myself, but I think I've seen it "out of the corner of my eye" when looking at code written by others.
Maybe I imagined it.
- EGreg 16y agoNo, you can't. You may be thinking of call_user_func_array, but once again you can indexed array. The most you can do -- which is what I am doing now -- is use the design pattern: function stuff($required1, $required2, $options = array()) { } This pattern works really well, and makes the function interface endlessly extensible. If we implemented named parameters in PHP, it would turn every EXISTING function into such a pattern, which would make functions evolve nicely instead of becoming monstrosities with default parameters in an arbitrary order: stuff(1, 2, null, true, null, 0, array(), '<br>')