PHP doesn't check for number of arguments passed?

I came from C++ / java background. I have been programming in PHP for a few months, but just today, after prolonged debugging, just realized php compiler doesn’t check for # of arguments passed vs. defined!

E.G.

[php]
function test($only_one, $no_use) {
print $only_one;
}

test(‘aa’, 5, 3);
[/php]
prints ‘aa’ … with arguments 5 and 3 ignored!

Problem is that I’ve been refactoring my code without IDE, and now I am not so confident about the result since I had assumed compiler would catch all cases where the arguments I pass in do not match the function definition.

What’s the best way to check my code to ensure number of arguments passed = arguments defined for all my functions?

they’re ignored because ur not doing anything with them. 3 arguements are being passed, but only 1 is being printed. the last number will be ignored because it cant be referenced.

PHP only throws warning for missing arguements.

I would suggest adding this to the beginning of your index on your dev environment
[php]ini_set(‘error_reporting’, E_ALL);
ini_set(‘display_errors’, ‘1’);[/php]

Not something you want activated on a live public site though.

And why aren’t you using an IDE? There are several free IDEs to choose from…

Btw, PHP is interpreted, not compiled :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service