neděle 22. listopadu 2009

A PHP pitfall (for a pythonist)

In python is quite natural to use keyword arguments in function calls, do not try that in PHP.
A header of PHP function function f1($a, $b, $c=3, $d=4) can lead to believe that it is allowed to address function arguments by theirs names in a function call. It is simply not true. What is worse, that following construction is in PHP in all ways correct.

f1($c=13, $d=14);

Because an assertion is an expression, the whole calling is semantic equivalent to:

$c=13
$d=14
f1(13, 14)

therefore f1 is called with $a=13, $b=14, $c=3, $d=4

Žádné komentáře:

Okomentovat