What are different types of errors available in Php

The Eduladder is a community of students, teachers, and programmers just interested to make you pass any exams. So we solve previous year question papers for you.
In eduladder you can Ask,Answer,Listen,Earn and Download Questions and Question papers.
Watch related videos of your favorite subject.
Connect with students from different parts of the world.
Apply or Post Jobs, Courses ,Internships and Volunteering opportunity. For FREE
See Our team
Wondering how we keep quality?
Got unsolved questions? Ask Questions

PHP-->View question

What are different types of errors available in Php ?

its about What are different types of errors available in Php


Asked On2019-09-06 15:46:36 by:Annaliya

Taged users:


Likes:
Be first to like this question

Dislikes:
Be first to dislike this question
Talk about this  Like  Dislike
View all qusetions
Answers

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 various types of errors in PHP but it contains basically four main type of errors.

 

Parse error or Syntax Error: It is the type of error done by the programmer in the source code of the program. The syntax error is caught by the compiler. After fixing the syntax error the compiler compile the code and execute it. Parse errors can be caused dues to unclosed quotes, missing or Extra parentheses, Unclosed braces, Missing semicolon etc

Example:

<?php

$x = "geeks";

y = "Computer science";

echo $x;

echo $y;

?>

Error:

 

PHP Parse error:  syntax error, unexpected '='

in /home/18cb2875ac563160a6120819bab084c8.php on line 3

Explanation: In above program, $ sign is missing in line 3 so it gives an error message.

 

Fatal Error: It is the type of error where PHP compiler understand the PHP code but it recognizes an undeclared function. This means that function is called without the definition of function.

Example:

<?php

 

function add($x, $y)

{

    $sum = $x + $y;

    echo "sum = " . $sum;

}

$x = 0;

$y = 20;

add($x, $y);

 

diff($x, $y);

?>

Error:

 

PHP Fatal error:  Uncaught Error:

Call to undefined function diff()

in /home/36db1ad4634ff7deb7f7347a4ac14d3a.php:12

 

Stack trace:

#0 {main}

  thrown in /home/36db1ad4634ff7deb7f7347a4ac14d3a.php on line 12

Explanation : In line 12, function is called but the definition of function is not available. So it gives error.

 

Warning Errors : The main reason of warning errors are including a missing file. This means that the PHP function call the missing file.

Example:

<?php 

 

$x = "GeeksforGeeks";

 

include ("gfg.php");

 

echo $x . "Computer science portal";

?>

Error:

 

PHP Warning:  include(gfg.php): failed to

open stream: No such file or directory in

/home/aed0ed3b35fece41022f332aba5c9b45.php on line 5

PHP Warning:  include(): Failed opening 'gfg.php'

 for inclusion (include_path='.:/usr/share/php') in

/home/aed0ed3b35fece41022f332aba5c9b45.php on line 5

Explanation: This program call an undefined file gfg.php which are not available. So it produces error.

 

Notice Error: It is similar to warning error. It means that the program contains something wrong but it allows the execution of script.

Example:

<?php  

 

$x = "GeeksforGeeks";

 

echo $x;

 

echo $geeks;

?>

Error:

 

PHP Notice:  Undefined variable: geeks in

/home/84c47fe936e1068b69fb834508d59689.php on line 5

Output:

 

GeeksforGeeks

Explanation: This program use undeclared variable $geeks so it gives error message.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 various types of errors in PHP but it contains basically four main type of errors.

 

Parse error or Syntax Error: It is the type of error done by the programmer in the source code of the program. The syntax error is caught by the compiler. After fixing the syntax error the compiler compile the code and execute it. Parse errors can be caused dues to unclosed quotes, missing or Extra parentheses, Unclosed braces, Missing semicolon etc

Example:

<?php

$x = "geeks";

y = "Computer science";

echo $x;

echo $y;

?>

Error:

 

PHP Parse error:  syntax error, unexpected '='

in /home/18cb2875ac563160a6120819bab084c8.php on line 3

Explanation: In above program, $ sign is missing in line 3 so it gives an error message.

 

Fatal Error: It is the type of error where PHP compiler understand the PHP code but it recognizes an undeclared function. This means that function is called without the definition of function.

Example:

<?php

 

function add($x, $y)

{

    $sum = $x + $y;

    echo "sum = " . $sum;

}

$x = 0;

$y = 20;

add($x, $y);

 

diff($x, $y);

?>

Error:

 

PHP Fatal error:  Uncaught Error:

Call to undefined function diff()

in /home/36db1ad4634ff7deb7f7347a4ac14d3a.php:12

 

Stack trace:

#0 {main}

  thrown in /home/36db1ad4634ff7deb7f7347a4ac14d3a.php on line 12

Explanation : In line 12, function is called but the definition of function is not available. So it gives error.

 

Warning Errors : The main reason of warning errors are including a missing file. This means that the PHP function call the missing file.

Example:

<?php 

 

$x = "GeeksforGeeks";

 

include ("gfg.php");

 

echo $x . "Computer science portal";

?>

Error:

 

PHP Warning:  include(gfg.php): failed to

open stream: No such file or directory in

/home/aed0ed3b35fece41022f332aba5c9b45.php on line 5

PHP Warning:  include(): Failed opening 'gfg.php'

 for inclusion (include_path='.:/usr/share/php') in

/home/aed0ed3b35fece41022f332aba5c9b45.php on line 5

Explanation: This program call an undefined file gfg.php which are not available. So it produces error.

 

Notice Error: It is similar to warning error. It means that the program contains something wrong but it allows the execution of script.

Example:

<?php  

 

$x = "GeeksforGeeks";

 

echo $x;

 

echo $geeks;

?>

Error:

 

PHP Notice:  Undefined variable: geeks in

/home/84c47fe936e1068b69fb834508d59689.php on line 5

Output:

 

GeeksforGeeks

Explanation: This program use undeclared variable $geeks so it gives error message.


Answerd on:2019-09-07 Answerd By:Tanisha-Garg

Likes:
Be first to like this answer

Dislikes:
Be first to dislike this answer
Talk about this  Like  Dislike

You might like this video:NEET Preparation Tips for Beginners after 10th class Result | Rank 3 | Manish
Watch more here

Watch more videos from this user Here

Learn how to upload a video and start earning here



Lets together make the web is a better place

We made eduladder by keeping the ideology of building a supermarket of all the educational material available under one roof. We are doing it with the help of individual contributors like you, interns and employees. So the resources you are looking for can be easily available and accessible also with the freedom of remix reuse and reshare our content under the terms of creative commons license with attribution required close.

You can also contribute to our vision of "Helping student to pass any exams" with these.
Answer a question: You can answer the questions not yet answered in eduladder.How to answer a question
Career: Work or do your internship with us.Work with us
Create a video: You can teach anything and everything each video should be less than five minutes should cover the idea less than five min.How to upload a video on eduladder