How do you trigger a E_NOTICE error in PHP8? A lot of things that used to be E_NOTICE in PHP7 has been increased in severity to E_WARNING, here are things i’ve already tried, that does not work:
echo $undefinedVar; // PHP>=8 E_WARNING
$array = [];
echo $array['undefined_key']; // PHP>=8 E_WARNING
class Test {
public $name;
}
$obj = new Test();
echo $obj->age; // PHP>=8 E_WARNING
$string = "abc";
echo $string[5]; // PHP>=8 E_WARNING
compact('undefinedVar'); // PHP>=8 E_WARNING
strlen(); // PHP>=8 ArgumentCountError
4
Answers
Found a way!
will trigger E_NOTICE:
EDIT: Ah dang! I just read that all wrong and triggered
E_WARNING
instead ofE_NOTICE
. 🙁OK, best I got is:
Not sure if that actually causes a disk read or not. Some slightly longer versions:
You can always trigger error yourself using
trigger_error()
function.See live example: https://3v4l.org/8eLEn
You will find the full list of notices raised by PHP 8.3 here.
A few examples (demo):
Output: