[php-src] Issue #8821: Using enum as array key in class constant correctly results in error, but line number is inaccurate

From: Date: Fri, 17 Jun 2022 17:13:04 +0000
Subject: [php-src] Issue #8821: Using enum as array key in class constant correctly results in error, but line number is inaccurate
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-241757@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/8821 Author: mwaggonerzam ### Description The following code: ```php <?php enum Alpha { case Foo; } class Bravo { public const C = [Alpha::Foo => 3]; } new Bravo(); ``` Resulted in this output: ``` Fatal error: Uncaught TypeError: Illegal offset type in /file.php:11 Stack trace: #0 {main} thrown in /file.php on line 11 ``` But I expected this output instead: ``` Fatal error: Uncaught TypeError: Illegal offset type in /file.php:8 Stack trace: #0 {main} thrown in /file.php on line 8 ``` **tl;dr:** Yes, I know you can't use an enum as an array key. The problem here is that PHP reported the error as being on the wrong line, making the real problem hard to find. To elaborate: PHP tells me the error is at new Bravo(), but the actual problem is on the line where the const is defined. In the trivial case above, figuring it out is easy, but in actual production code, the new might be in another file entirely and class Bravo might be hundreds of lines long, concealing where the error really is. Yes, I know static analysis tools would correctly find the problem; this is still an error in PHP's engine. I reproduced this using 3v4l.org, in addition to on my local machine, just to make sure any of my ini settings or extensions weren't affecting things. ### PHP Version PHP 8.1.7 ### Operating System _No response_

« previous php.bugs (#241757) next »