Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ReflectionClass::getConstants() gives an error depending on the order of constants definition #8080

Closed
@bsod85

Description

@bsod85

Description

The following code:

<?phpclass A {constLIST = [self::TEST =>'Test',    ];privateconstTEST ='test';}class Bextends A {    }$r =newReflectionClass(B::class);print_r($r->getConstants());

Resulted in this output:

Fatal error: Uncaught Error: Undefined constant self::TEST in /in/FuJAW:15Stack trace:#0 /in/FuJAW(15): ReflectionClass->getConstants()#1 {main}  thrown in /in/FuJAW on line 15

But I expected this output instead:

Array(    [LIST] => Array        (            [test] => Test        ))

that is the output you get by defining the constants this way:

privateconstTEST ='test';constLIST = [self::TEST =>'Test',];

PHP Version

8.1.2

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


      [8]ページ先頭

      ©2009-2025 Movatter.jp