show php Errors with Example

Thursday , 6, May 2021 Leave a comment

how to show all php Errors . In this tutorial, you will learn how to show all errors in PHP.

And as well as learn, how to reporting all errors in PHP.

Error is the fault or mistake in a program. It can be several types. Error can occur due to wrong syntax or wrong logic. It is a type of mistakes or condition of having incorrect knowledge of the code.

There are four three of errors in PHP are:

  1. Warning Error 
  2. Fatal Error
  3. Parse Error

Warning Error 

The main reason to occurs warning errors is to include a missing file, calling a function with incorrect parameters, it also does not stop the execution of PHP script. It only reminds you that there is a problem in the script. in this time you can see this warning in the undefined variable in PHP script. We will show you both examples

The following example represents the warning error:

<?php
$x="your variable";
echo $x;
echo $y;
?>

Output:

your variable
Warning: Undefined variable $y in D:\xampp\htdocs\php\index.php on line 4

In this example, output print only $x variable . As well as print $y variable without define. the Warning occurs and display the $y When you don’t create $y variable.

<?php
include ("external_file.php");
?>

Output:

Warning: include(external_file.php): Failed to open stream: No such file or directory in D:\xampp\htdocs\php\index.php on line 2

Warning: include(): Failed opening 'external_file.php' for inclusion (include_path='D:\xampp\php\PEAR') in D:\xampp\htdocs\php\index.php on line 2

In this example, include any PHP file that does not exist in your application. At that time, it displays a warning that failed to include it.

Fatal Error

If you call to undefined functions and classes , at the time fatal error occurs. The Fatal error does stop the execution of the PHP script and it is show fatal error message

<?php
function hello(){
    echo "hello world";
   }
   hello();
   hey();
?>

Output:

hello world
Fatal error: Uncaught Error: Call to undefined function hey() in D:\xampp\htdocs\php\index.php:6 Stack trace: #0 {main} thrown in D:\xampp\htdocs\php\index.php on line 6

hey() function is called but it is not defined. At this time, the fatal error comes and stops the execution of the script with an error message.

Parse Error

The parse error happens, when you type any wrong script. Parse error does also stops the execution of the script and it show parse error or syntax error message.

The following main reason for syntax or parse errors message:

Unclosed quotes
Missing or Extra parentheses
Unclosed braces
Missing semicolon


The following example represents the parse error:

<?php
echo "1"
echo "1";
?>

Output:

Parse error: syntax error, unexpected token "echo", expecting "," or ";" in D:\xampp\htdocs\php\index.php on line 3

In this example, you are missed a semicolon. At that time it occurs.

Dynamic dependent select box using jQuery, Ajax, and PHP Text to speech in PHP with Google Translate

Leave a Reply

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