Access to undefined nested index leads to error 503
Description
The following code:
<?php
$myArray = [];
$firstIndex = "AA-123123-BB";
$secondIndex = 'M';
$value = $myArray[$firstIndex][$secondIndex];
Resulted in this output:
Server error 503
But I expected this output instead:
Warning: Undefined array key
PHP Version
PHP 8.1.16
Operating System
No response
@NoxArt your snippet works as expected (tested at https://onlinephp.io/), so probably there's some important context missing here. Don't you have some framework with custom error handler, which converts warnings to exceptions and display_errors off? Or something like that?
Thank you for reply
Display_errors in on, Error reporting is E_ALL There are custom error handlers: Nette Tracy (not the whole Nette framework) and one that just writes it into a file
I did not run into such issue prior to upgrading to 8.1 (7.3 > 7.4 > 8.0 > 8.1)
I would have posted a better sample, but it's a code preceded by thousands of lines and works over thousands of lines of CSV data (containing private customer information), so I didn't know how to convey that information
When I fixed this code so that the index would be there it started working fine and fast (given what it should do) again
@NoxArt
What I get with your snippet and Tracy in debug mode (Debugger::enable();):

what I get without a debug mode
Both with php-fpm 8.1.14 and nginx.
Nevertheless, this isn't a php bug.
Btw, was it really working in PHP8.0? Because there was a change from Notice to Warning between PHP7.4 to PHP8.0, so i would expect the same behaviour between php8 and php8.1 (and I dont see anything related in "Deprecations and backward compatibility breaks" https://www.php.net/releases/8.1/en.php)
@NoxArt i think you use something like this
Debugger::$strictMode = true;
Debugger::$strictMode = E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED;
Then the page shows the error with the response code 500, which is probably transferred to Server error 503 by webserver/proxycache? Can you share a screenshot of the error?
..but just fix the indexes end everything will be OK :)
@nielsdos I think we can go directly to Status: Invalid here :)
Thank you, I think you spent here more time than needed here, it's just that this behavior was super puzzling to me You can close it then
Seems like you are correct @pospjan , thank you for your great support! Looks like this is indeed specific to the framework error handling. So I'm closing this as invalid.