I want to pass a parameter to a function as below for clarity. It doesn't give any error. But is this a bad practice. Do I have to avoid this.
test('','','',$d='text','');
function test($a, $b, $c, $d, $e){
}
I want to pass a parameter to a function as below for clarity. It doesn't give any error. But is this a bad practice. Do I have to avoid this.
|
|||||||||||||||||
closed as unclear what you're asking by Simon, Bart van Ingen Schenau, GlenH7, psr, MichaelT Jan 23 '14 at 1:16Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question. |
|||||||||||||||||
|
I actually find this question interesting :) My take is that this is a bad practice today in PHP. That kind of syntax is typical of Python which has a feature called "named parameters" that allows calling a function without using the same order of variable calls. There is an RFC in the php community to add this syntax to the language: https://wiki.php.net/rfc/named_params The internal discussion about this feature is not finished yet, personally I would like to have this feature. As of today (PHP 5.5), you get no benefit at all in using this syntax as you are just evaluating the variable. |
|||
Did this answer by Pascalc help you? It's easy to give back. Sign up to get started. | |||
|
Is there any reason to assign the $str variable inline like that? Does it improve clarity at all? I believe it's just evaluating
It's the same as
It's a bit weird looking and may be misleading when reading the code later so I would avoid doing that. |
|||||
|