Error Types in PHP


Errors in PHP manifest when script execution encounters problems. PHP categorizes errors from basic notices to severe fatal errors which stop the execution process.

php-error

Parse Error / Syntax Error (E_PARSE)

A Syntax Error in PHP happens when there is a mistake in the code syntax.

 

<?php
echo "Hello, world!" // Missing semicolon
?> 

Fatal Error (E_ERROR)

  • A function or class does not exist
  • A file is missing
  • Memory limits are exceeded

<?php
nonExistentFunction(); // Fatal Error
?> 

Fatal Error (E_ERROR)

Non-fatal error. Something is wrong, but the script continues to run.

 


<?php
include("missing_file.php"); // Warning: file not found
echo "Still runs!";
?> 

Notice (E_NOTICE)

Occurs when you try to access an undefined variable or perform unusual behavior.

 


<?php
echo $name; // Notice: Undefined variable
?> 

Error Overview

Constant Description
E_ERROR Fatal runtime errors
E_WARNING Runtime warnings (non-fatal)
E_PARSE Compile-time parse errors
E_NOTICE Notices for undefined behavior
E_DEPRECATED Warns about deprecated features
E_ALL All errors and warnings



OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.