PHP Error Constant E_WARNING
The PHP E_WARNING Constant is a non-fatal run time error and E_WARNING Constant has an Integer value 2.
PHP engine doesn't halt the script execution when it arises and it logs the warning in error_log file. When an E_WARNING occurs, you may not lose whatever data the program was currently processing
and it mostly occurs in failure of outsource like unknown file access, database authentication and wrong header information.
Example: #1- PHP Error Constant E_WARNING
Try to include a file abc.php which is not exist on the drive, it will throw a warning.
PHP Input Screen
<?php
ini_set("display_startup_errors", 1);
ini_set("display_errors", 1);
error_reporting(-1);
include("abc.php");
// The E_WARNING won't stop the code execution
echo("Code executed successfully.");
PHP Output Screen
Warning: include(abc.php): failed to open stream: No such file or directory in ~\Documents\php-error-constants.php on line 6
Warning: include(): Failed opening 'abc.php' for inclusion (include_path='.;C:\php\pear') in ~\Documents\php-error-constants.php on line 6
Code executed successfully.
Example: #2- PHP Error Constant E_WARNING
Try to redirect to an external url using PHP header after a echo statement, it will throw a warning.
PHP Input Screen
<?php
ini_set("display_startup_errors", 1);
ini_set("display_errors", 1);
error_reporting(-1);
echo("Redirect to https://www.bbminfo.com");
header("Location: https://www.bbminfo.com");
PHP Output Screen
Redirect to https://www.bbminfo.com
Warning: Cannot modify header information - headers already sent by (output started at ~\Documents\php-error-constants.php:6) in ~\Documents\php-error-constants.php on line 8
Thousands Lived without Love, but not without water. So SAVE WATER.
Example: #3- PHP Error Constant E_WARNING
Try to call a method without all mandatory arguments, it will throw a warning.
PHP Input Screen
<?php
ini_set("display_startup_errors", 1);
ini_set("display_errors", 1);
error_reporting(-1);
$strArray = explode("Hello World");
PHP Output Screen
Warning: explode() expects at least 2 parameters, 1 given in ~\Documents\php-error-constants.php on line 6
Thousands Lived without Love, but not without water. So SAVE WATER.
Example: #4- PHP Error Constant E_WARNING
Try to pop an element using a built-in library method of an undefined array variable, it will throw a warning.
PHP Input Screen
<?php
ini_set("display_startup_errors", 1);
ini_set("display_errors", 1);
error_reporting(-1);
// Passing an undefined array variable
array_pop($undefinedArray);
PHP Output Screen
Warning: array_pop() expects parameter 1 to be array, null given in ~\Documents\php-error-constants.php on line 7
BBMINFO