reefat Posted January 3, 2011 Share Posted January 3, 2011 I have been scripting (some may say programming) in PHP for last 5 years but never faced this issue. Interesting! Say for example, I created a custom function with one argument: function myFunc($arg1) { echo $arg1; } Now, if I call this function without supplying any argument it doesn't give any error/warning. Any other high level language like C++ or Java would produce error in this case. So, I had to modify my code as follows: function myFunc($arg1) { if (!isset($arg1)) { echo "Missing argument 1"; } echo $s; } But this is annoying. Now I have to add these EXTRA lines of code in every function and class methods I have created. Is there any shortcut/easy method that the script will always produce an error if its missing any required argument? I have tried with adding error_reporting(E_ALL); at the very beginning of my code. But it still didn't work out. By the way, I am using PHP 5.3.1 on Apache/2.2.14 (Unix). Any suggestion will be appreciated. Link to comment https://forums.phpfreaks.com/topic/223261-strange-no-warning-for-missing-argument/ Share on other sites More sharing options...
Pikachu2000 Posted January 3, 2011 Share Posted January 3, 2011 It generates a missing argument warning for me on 5.2.14. I haven't installed 5.3.x yet, so I can't check it on that . . . Link to comment https://forums.phpfreaks.com/topic/223261-strange-no-warning-for-missing-argument/#findComment-1154184 Share on other sites More sharing options...
PFMaBiSmAd Posted January 3, 2011 Share Posted January 3, 2011 Do you have display_errors set to ON as well? Link to comment https://forums.phpfreaks.com/topic/223261-strange-no-warning-for-missing-argument/#findComment-1154185 Share on other sites More sharing options...
BlueSkyIS Posted January 3, 2011 Share Posted January 3, 2011 It generates a missing argument warning for me on 5.2.14. I haven't installed 5.3.x yet, so I can't check it on that . . . Generates missing argument warning in PHP 5.3.2 here. Link to comment https://forums.phpfreaks.com/topic/223261-strange-no-warning-for-missing-argument/#findComment-1154186 Share on other sites More sharing options...
reefat Posted January 3, 2011 Author Share Posted January 3, 2011 Oops! Forgot to mention that I'm using a custom error handler set by set_error_handler("__error_handler"); . E_COMPILE_WARNING was turned off there. This was causing the problem. Sorry for the confusion. And thanks a lot for the cooperation. Link to comment https://forums.phpfreaks.com/topic/223261-strange-no-warning-for-missing-argument/#findComment-1154197 Share on other sites More sharing options...
ManiacDan Posted January 3, 2011 Share Posted January 3, 2011 PHP, like Perl, has a "no complaints mode." Use this line to turn error-reporting on: error_reporting(E_ALL); Put that at the top of your script, or edit your PHP.ini file, and you'll see all the errors you've been missing. Also, as a side note, it's possible to make a function argument optional in PHP by supplying it with a default value: function myFunc ( $a = "Hello, World!" ) {} -Dan Link to comment https://forums.phpfreaks.com/topic/223261-strange-no-warning-for-missing-argument/#findComment-1154198 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.