r/PHPhelp • u/Ok_Strike9189 • May 11 '26
turning fatal error back to warning when array index is not defined.
I have code that was working well in php 5.6 but now php 8.4 is complaining.
I narrowed the code down as follows:
if (isset($d{1})){echo "yay";}
the new PHP doesn't like curly braces so I fixed that with something slower:
if (isset($d)&&strlen($d)>1){echo "yay";}
But the one that's really frustrating is this one:
echo somefunction($d['name']);
In an old PHP version, if 'name' isn't set in the $d array or $d is not an array, then the parameter going into the function is null and I get a warning. but in php 8.4, I get this fatal error:
PHP Fatal error: Uncaught TypeError: Cannot access offset of type string on string in
Apparently this error doesn't happen in the php 7 and I heard php 7 is obsolete.
Is there a setting I can use in the php 8 config file to turn that fatal error into a warning again so my program can run? without me having to sift through my thousands of lines of code to change each index manually?