Re: Named parameters
| From: | Gregory | Date: | Sat, 16 Oct 2010 15:38:30 +0000 |
| Subject: | Re: Named parameters | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-49920@lists.php.net to get a copy of this message | ||
See below:
On 10/16/10 11:33 AM, Reindl Harald wrote:
The topic are "named parameters" Am 16.10.2010 17:07, schrieb Gregory:So now I can use $options?What ARE you talking about? On 10/16/10 5:55 AM, Reindl Harald wrote:Am 15.10.2010 19:59, schrieb G M:It's true that you can already do something similar -- although not as easily. I personally always use this pattern:Is it not and your sample is one of the greatest mistakes you can do * At this moment $options will be set to an empty array in the caller Are you implying that calling stuff($a, b) will now set $options = array() in the CALLER?
* You must use the correct order because $options does not matter What does this mean, $options does not matter? You must pass parameters in the correct order, that's really the whole point of this pattern -- sometimes you don't want this.
* The sample is dangerous for performance and side-effects Dangerous? Which part, default parameters are dangerous, or extract() is dangerous? If the latter, don't use extract().
And does this even compile?function stuff($required1, $required2, $options = array()) { extract($options); }What you can do to make your code readable is the following function stuff($required1, $required2, /**$options*/array()) { extract($options); } Wait, this is *more* readable than $options = array()?