Skip to content

Misleading error reporting when using a non-existent constant in a static variable initializer  #10356

Closed
@TimWolla

Description

@TimWolla

Description

The following code (https://3v4l.org/la8tX):

<?php

final class Foo {
    public static $foo = [
        'foo' => DOES_NOT_EXIST,
    ];
}

new Foo();

Resulted in this output:

Fatal error: Uncaught Error: Undefined constant "DOES_NOT_EXIST" in /in/la8tX:9
Stack trace:
#0 {main}
  thrown in /in/la8tX on line 9

But I expected this output instead:

Some indication that the broken constant is in line 5, because line 9 clearly does not contain any constants.

PHP Version

PHP 8.2.1

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions