E_WARNING (2) identifies a runtime warning. Execution normally continues, although a custom error handler can change that behavior. Some diagnostics in these older examples changed in PHP 7 or PHP 8.
A simple example
E_WARNING
Start withAn include of a missing practice file
Do thisAttempt to include it
ResultA warning is reported
With the default handler, include reports the missing file and execution can continue.
Example: #1- PHP Error Constant E_WARNING
A timetable page includes a shared component whose file is missing on the preview machine. The include normally raises a warning and the caller can continue.
PHP diagnosticE_WARNING
Output excerptWarning: include(abc.php): failed to open stream: No such file or directory in ~\Documents\ph…
PHP source code
<?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.");
Output
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.
Advertisements
Example: #2- PHP Error Constant E_WARNING
A booking page writes text before setting a response header. The diagnostic depends on whether the server has already sent that output.
PHP diagnosticE_WARNING
First output lineRedirect to https://www.bbminfo.com
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
Example: #3- PHP Error Constant E_WARNING
A studio form calls a helper without a required argument. Check the historical example against modern PHP, which raises ArgumentCountError for this call.
PHP diagnosticE_WARNING
Output excerptWarning: explode() expects at least 2 parameters, 1 given in ~\Documents\php-error-constants.…