Friday, July 3, 2009

PHP Functions - too dynamic?

Today I was working on an application, where I found it strange when my application function is not working as I wanted it to be.

After a quick debug, I found out that it's because:

<?php
func($param1,$param2,$param3); // the way i am calling the function

function func($params){
// i declared func this way, and accepted $params as array of parameters 1, 2 and 3.
}
?>


Ended up, function "func" read in only $param1 and not $param2 and $param3. On top of that, it does not display any error or warning.

Note that when calling any PHP functions, you can specify additional parameters/arguments than what is defined in declaration. However, you cannot specify number of parameters less than declared.

No comments: