Beginners Logo
  • होम
  • ताज़ा खबरें
  • करियर गाइडेंस
  • जॉब ओपनिंग्स
  • एडमिशन
  • परीक्षा की जानकारी
  • एडमिट कार्ड
  • रिजल्ट
  • सामान्य ज्ञान
  1. Home
  2. Tutorial
  3. Php
  4. Php Error

PHP Error

PHP errors can be classified into various categories based on their severity and nature. Understanding these errors is crucial for effective debugging and development. Here's a breakdown:

1. Parse Errors (Syntax Errors)

These are caused by incorrect syntax, like missing semicolons, unmatched brackets, etc. 
Example:

<?php
echo "Hello, World
?>

The above code will produce a parse error because it's missing the closing semicolon.

2. Fatal Errors

These errors halt the execution of the script. A fatal error is generally issued if PHP understands what you've asked it to do but can't perform the task. 
Example:

<?php
function greet() {
    echo "Hello, World!";
}

greetting();
?>

The above code will produce a fatal error since the function `greetting()` is not defined.

3. Warning Errors

These errors don't stop the script from continuing its execution. They're raised, for instance, when you include() a file that doesn't exist. 
Example:

<?php
include("non_existent_file.php");
echo "Hello, World!";
?>

Despite the warning, the script will continue to run and print "Hello, World!".

4. Notice Errors

These are minor errors and suggest that the script might be prone to bugs or unexpected behaviors. They do not halt the script execution. 
Example:

<?php
$var = "Hello, World!";
echo $va;
?>

The code will produce a notice since the variable `$va` is not defined.

5. Deprecated Warnings

These warnings indicate that a function or feature being used in the script is outdated and might not be supported in future versions. 
Example:

<?php
$var = split(':', 'Hello:World!');
?>

The `split()` function is deprecated, so using it will raise a deprecated warning.

Handling Errors:

PHP provides mechanisms to handle errors gracefully using `set_error_handler()`, `trigger_error()`, etc.

<?php
function customError($errno, $errstr) {
  echo "Error: [$errno] $errstr";
}

set_error_handler("customError", E_USER_WARNING);

$test=2;

if ($test>1) {
  trigger_error("Value must be 1 or below", E_USER_WARNING);
}
?>

The above script will trigger a custom error.

Reporting Levels:

You can also control what kinds of errors should be reported using `error_reporting()` function and related configurations in `php.ini`:

  • `E_ALL`: All errors and warnings
  • `E_ERROR`: Fatal runtime errors
  • `E_WARNING`: Runtime warnings
  • `E_PARSE`: Compile-time parse errors
  • `E_NOTICE`: Run-time notices
  • etc.

For instance:

<?php
// Report all errors
error_reporting(E_ALL);
?>

Final Thoughts: Always remember to turn off error reporting or set it to log errors instead of displaying them when moving your application from a development environment to production. Displaying errors can expose sensitive information. Always use logs in a production environment and monitor them regularly.

UPCET Exam

UPCET Exam

Click Here

SAAT Exam

SAAT Exam

Click Here

MHT CET Exam

MHT CET Exam

Click Here

IPU CET Exam

IPU CET Exam

Click Here

KCET Exam

KCET Exam

Click Here

COMEDK UG Exam

COMEDK UG Exam

Click Here

VITEEE Exam

VITEEE Exam

Click Here

BITSAT

BITSAT

Click Here

DSAT: Dayanand Sagar Admission Test

DSAT: Dayanand Sagar Admission Test

Click Here

Career In Animation in india

Career In Animation in india

Click Here

Merchant Navy Courses in india

Merchant Navy Courses in india

Click Here

Interior Design Career in india

Interior Design Career in india

Click Here

UGC NET Exam

UGC NET Exam

Click Here

B. Ed Exam

B. Ed Exam

Click Here

AFCAT - Air Force Common Admission Test

AFCAT - Air Force Common Admission Test

Click Here

GATE Exam

GATE Exam

Click Here

Joint Entrance Examination (JEE)

Joint Entrance Examination (JEE)

Click Here

Common Admission Test (CAT)

Common Admission Test (CAT)

Click Here

CDS - Combined Defence Services Exam

CDS - Combined Defence Services Exam

Click Here

अन्य खबरें

  • प्राइवेट नौकरी अपडेट: Testbook में कंटेंट राइटर की नई वैकेंसी, ग्रेजुएट करें अप्लाई, दिल्ली में मिलेगी फुल टाइम जॉब

  • मार्च में सरकारी नौकरी के सुनहरे मौके! बैंक, पुलिस, डाक विभाग से लेकर असिस्टेंट प्रोफेसर तक कई भर्तियाँ जारी

  • केवीएस बाल वाटिका एडमिशन 2025: केंद्रीय विद्यालय में नर्सरी, एलकेजी, यूकेजी में प्रवेश शुरू, आवेदन प्रक्रिया और अंतिम तिथि जानें

  • नीट यूजी 2025 परीक्षा रजिस्ट्रेशन शुरू: फीस, एडमिट कार्ड, परीक्षा तिथि और रिजल्ट से जुड़ी सभी जरूरी जानकारी

  • यूपी बीएड प्रवेश परीक्षा 2025: आवेदन की तारीख घोषित, जानें रजिस्ट्रेशन प्रक्रिया, परीक्षा तिथि और अन्य जरूरी जानकारी

  • Bihar DElED Exam 2025: डीएलएड अभ्यर्थियों के लिए जरूरी अपडेट, आवेदन में हुई गलती ऐसे करें सुधार, अंतिम तिथि से पहले पूरा करें प्रक्रिया

  • PHP Tutorial
    • PHP Tutorial
    • PHP Introduction
    • PHP Installation
    • PHP Syntax
    • PHP Comments
    • PHP Variables
    • PHP Echo / Print
    • PHP Data Types
    • PHP Strings
    • PHP Numbers
    • PHP Math
    • PHP Constants
    • PHP Operators
    • PHP If...Else...Elseif
    • PHP Switch
    • PHP Loops
    • PHP Functions
    • PHP Arrays
    • PHP Superglobals
    • PHP RegEx
    • PHP Forms
    • PHP Form Handling
    • PHP Form Validation
    • PHP Form Required
    • PHP Form URL/E-mail
    • PHP Form Complete
    • PHP Advanced
    • PHP Date and Time
    • PHP Include
    • PHP File Handling
    • PHP File Open/Read
    • PHP File Create/Write
    • PHP File Upload
    • PHP Cookies
    • PHP Sessions
    • PHP Filters
    • PHP Filters Advanced
    • PHP Callback Functions
    • PHP JSON
    • PHP Exceptions
    • PHP OOP
    • PHP What is OOP
    • PHP Classes/Objects
    • PHP Constructor
    • PHP Destructor
    • PHP Access Modifiers
    • PHP Inheritance
    • PHP Abstract Classes
    • PHP Interfaces
    • PHP Traits
    • PHP Static Methods
    • PHP Static Properties
    • PHP Namespaces
    • PHP Iterables
    • MySQL Database
    • MySQL Connect
    • MySQL Create DB
    • MySQL Create Table
    • MySQL Insert Data
    • MySQL Get Last ID
    • MySQL Insert Multiple
    • MySQL Prepared
    • MySQL Select Data
    • MySQL Where
    • MySQL Order By
    • MySQL Delete Data
    • MySQL Update Data
    • MySQL Limit Data
    • AJAX Intro
    • AJAX Database
    • AJAX Live Search
    • AJAX Poll
    • PHP Examples
    • PHP Compiler (Editor)
    • PHP Quiz
    • PHP Exercises
    • PHP Certificate
    • PHP Reference
    • PHP Overview
    • PHP Array
    • PHP Calendar
    • PHP Date
    • PHP Directory
    • PHP Error
    • PHP Exception
    • PHP Filesystem
    • PHP Filter
    • PHP FTP
    • PHP Keywords
    • PHP Mail
    • PHP Misc
    • PHP MySQLi
    • PHP Network
    • PHP Output Control
    • PHP Stream
    • PHP String
    • PHP Variable Handling
    • PHP XML Parser
    • PHP Zip
    • PHP Timezones
  • Other Tutorials
    • Angular
    • CSS
    • Javascript
    • Mysql
    • Node JS
    • PHP Tutorial
    • Python
    • React Tutorial