Skip to content

Add Downgrade ReflectionClassConstant::IS_* on get constant name and value from ReflectionClass #6877

@samsonasik

Description

@samsonasik

Feature Request

Given the following code:

class A
{
    public const A1 = 'A1 Value';
    protected const A2 = 'A2 Value';
    private const A3 = 'A3 Value';
}

in PHP 8.0+, we can code:

$reflectionClass = new ReflectionClass('A');
+var_dump($reflectionClass->getConstants(ReflectionClassConstant::IS_PUBLIC));

It stil no downgrade rule to downgrade it to be like this in PHP 7.x:

$reflectionClass = new ReflectionClass('A');
+$reflectionClassConstants = $reflectionClass->getReflectionConstants();
+$result = [];
+array_walk($reflectionClassConstants, function ($value) use (&$result) {
+    if ($value->isPublic()) {
+       $result[$value->getName()] = $value->getValue();
+    }
+});
+var_dump($result);

Ref #6864 which currently manually fixed by downgrade to php 7.x compatible syntax at rectorphp/rector-src#1474

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions