Skip to content

Add RealClassClassConstantReflection::isFinalByKeyword() for native final class constant #14171

@samsonasik

Description

@samsonasik

Feature request

Currently, the isFinal() mark final even on non-native constant:

/**
 * @final
 */
public const BAR = 'Bar';

Like ClassReflection, I think isFinalByKeyword() should be added for detect native final. Currently, the workaround is to be something like:

// Get the native ReflectionClassConstant
$declaringClass = $reflection->getDeclaringClass();
$nativeReflectionClass = $declaringClass->getNativeReflection();
$constantName = $reflection->getName();

// ensure native ->isFinal() exists
// @see https://3v4l.org/korKr#v8.0.11
if (PHP_VERSION_ID >= 80100) {
    $nativeReflection = $nativeReflectionClass->getReflectionConstant($constantName);
    $memberIsFinal = $nativeReflection instanceof ReflectionClassConstant && $nativeReflection->isFinal();
} else {
    $memberIsFinal = false;
}

Did PHPStan help you today? Did it make you happy in any way?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions