0% found this document useful (0 votes)
7K views

PHP Error

The document discusses different types of PHP errors including warning errors, notice errors, parse errors, and fatal errors. It provides examples of each error type and explains the causes and how they affect code execution.

Uploaded by

Mayank Singh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7K views

PHP Error

The document discusses different types of PHP errors including warning errors, notice errors, parse errors, and fatal errors. It provides examples of each error type and explains the causes and how they affect code execution.

Uploaded by

Mayank Singh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

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.

The four types of PHP errors are:

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.

The most common causes of warning errors are:

 Calling on an external file that does not exist in the directory


 Wrong parameters in a function

For instance:

<?php
echo "Warning error"';
include ("external_file.php");
?>

As there is no “external_file”, the output displays a message, notifying it failed to include


it. Still, it doesn’t stop executing the script.
Notice Error
Notice errors are minor errors. They are similar to warning errors, as they also don’t
stop code execution. Often, the system is uncertain whether it’s an actual error or
regular code. Notice errors usually occur if the script needs access to an undefined
variable.

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.

Parse Error (Syntax)


Parse errors are caused by misused or missing symbols in a syntax. The compiler
catches the error and terminates the script.

Parse errors are caused by:

 Unclosed brackets or quotes


 Missing or extra semicolons or parentheses
 Misspellings

For example, the following script would stop execution and signal a parse error:
<?php
echo "Red";
echo "Blue";
echo "Green"
?>

It is unable to execute because of the missing semicolon in the third line.

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.

There are three (3) types of fatal errors:

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)

For instance, the following script would result in a fatal error:

<?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

to Required. Specifies the receiver / receivers of the email

subject Required. Specifies the subject of the email. Note: This parameter cannot


newline characters

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).

Note: When sending an email, it must contain a From header. This can be


parameter or in the php.ini file.
parameters Optional. Specifies an additional parameter to the sendmail program (the o
sendmail_path configuration setting). (i.e. this can be used to set the enve
address when using sendmail with the -f sendmail option)

You might also like