PHP Error
PHP Error
PHP Error occurs when something is wrong in the PHP code. The error can be as
simple as a missing semicolon, or as complex as calling an incorrect variable.
To efficiently resolve a PHP issue in a script, you must understand what kind of problem
is occurring.
1. Warning Error
2. Notice Error
3. Parse Error
4. Fatal Error
Warning Error
A warning error in PHP does not stop the script from running. It only warns you that
there is a problem, one that is likely to cause bigger issues in the future.
For instance:
<?php
echo "Warning error"';
include ("external_file.php");
?>
Example:
<?php
$a="Defined error";
echo "Notice error";
echo $b;
?>
In the script above, we defined a variable ($a), but called on an undefined variable ($b).
PHP executes the script but with a notice error message telling you the variable is not
defined.
For example, the following script would stop execution and signal a parse error:
<?php
echo "Red";
echo "Blue";
echo "Green"
?>
Fatal Error
Fatal errors are ones that crash your program and are classified as critical errors. An
undefined function or class in the script is the main reason for this type of error.
1. Startup fatal error (when the system can’t run the code at installation)
2. Compile time fatal error (when a programmer tries to use nonexistent data)
3. Runtime fatal error (happens while the program is running, causing the code to
stop working completely)
<?php
function sub()
{
$sub=6-1;
echo "The sub= ".$sub;
}
div();
?>
The output tells you why it is unable to compile, as in the image below:
Definition and Usage
The mail() function allows you to send emails directly from a script.
Syntax
mail(to,subject,message,headers,parameters);
Parameter Values
Parameter Description
message Required. Defines the message to be sent. Each line should be separated w
Lines should not exceed 70 characters.
Windows note: If a full stop is found on the beginning of a line in the mes
removed. To solve this problem, replace the full stop with a double dot:
<?php
$txt = str_replace("\n.", "\n..", $txt);
?>
headers Optional. Specifies additional headers, like From, Cc, and Bcc. The addition
be separated with a CRLF (\r\n).