Errors in php – PHP Lessons

elephant_phpWhen we write code, we will get some errors. This is normal. Any programmer will get errors. PHP in this case is trying to show us where there was an error and the line of code number.

The most popular error in PHP – we do not put “;” at the end of the expression:

<?php
$user_name = "Martin";
echo $user_name;
unset($user_name)
echo $user_name;
?>

You’ll get the following error:

Parse error: syntax error, unexpected T_ECHO, expecting ‘;’ in /htdocs/test.php on line 5.

Let’s talk about the levels of php errors. There are several levels of errors but we need to know basic four of them.

The first level of error – is PARSE ERROR

You do not need to be afraid. So what does it mean? It means when the PHP code gets it parses, the code itself still does not begin to run. For example, we have given the book proofreader and he begins to check it out but not yet a leaf had not been printed. Once proofreader checks and say that everything is in order the book will be printed. Here is the same. Proofreader find the error in our code and display us the error before code was executed.

The second and third level of error – FATAL ERROR and WARNING

When the PHP checked the code but have not run it(ie no syntax errors were not found), he tries to runs it. Here it may be faced with the problem, for example, we have a file open which does not exist. It turns out that from the point of view of the syntax is correct but some parts of the program may not work. It is a second level of errors in PHP. What is the difference between FATAL ERROR and WARNING? The difference is that when we get FATAL ERROR is an error and the code is complete, it stops working. A WARNING – this is just a warning. PHP just dumped us this error but the code will continue to work.

The fourth level of error – NOTICE

This is the simplest error in PHP or I would call it just a warning. It’s such an easy level warning about something little meaningful. However we would recommend you to fix those errors if you want good code.

This entry «error_reporting (0);” prohibits to display all the errors in the user’s browser. We do not recommend you to do that without really good reason.

Leave a Reply

Your email address will not be published. Required fields are marked *