In this tutorial we will discuss runtime errors in PHP caused by functions.
If your script call to undefined function or the function does exist, but the number of parameters is wrong you will receive an error.
It is easy to call a function that does not exist.
You can call function that does not exist in the current script but might exist elsewhere. If your code contains a call to a nonexistent function, such as wrong_name_function(); or missing_function(); – you will receive an error message from the parser similar to this:
Fatal error: Call to undefined function: wrong_name_function()
in /home/public_html/file.php on line 3
Also, if you call a function that exists but call it with an incorrect number of parameters,
you will receive a warning.
The function two_strings() requires two strings – for example bottle and size of the bottle ‘“ and you run the function just like this:
-
<?php
-
-
two_strings();
-
-
?>
You will get the following warning:
Warning: Wrong parameter count for strstr() in
/home/public_html/bottles.php on line 3
That same statement within the following script is equally wrong:
-
<?php
-
-
if($var == 4)
-
-
{
-
-
two_strings();
-
-
}
-
-
?>
Just in case when the variable $var is equal to 4 the call to two_strings() will not occur, and you wont receive warning message.
The PHP interpreter does not pars sections of the code that are not needed for the current execution of the script. In this case only testing will help this error to appear and to be fixed.
If you call function incorrectly the resulting error messages identify the exact line and function call that are causing the problem, they are equally easy to fix.They are difficult to find only if your testing process is poor and does not test all conditionally executed code. So it is really good idea to execute all your code lines at least ones.