Skip to content

Implement ReflectionProperty::isFinal() #15919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -5960,7 +5960,7 @@ ZEND_METHOD(ReflectionProperty, getModifiers)
{
reflection_object *intern;
property_reference *ref;
uint32_t keep_flags = ZEND_ACC_PPP_MASK | ZEND_ACC_PPP_SET_MASK | ZEND_ACC_STATIC | ZEND_ACC_READONLY | ZEND_ACC_ABSTRACT | ZEND_ACC_VIRTUAL;
uint32_t keep_flags = ZEND_ACC_PPP_MASK | ZEND_ACC_PPP_SET_MASK | ZEND_ACC_STATIC | ZEND_ACC_READONLY | ZEND_ACC_ABSTRACT | ZEND_ACC_VIRTUAL | ZEND_ACC_FINAL;

if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
Expand Down Expand Up @@ -6604,6 +6604,11 @@ ZEND_METHOD(ReflectionProperty, getHook)
reflection_method_factory(hook->common.scope, hook, NULL, return_value);
}

ZEND_METHOD(ReflectionProperty, isFinal)
{
_property_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_FINAL);
}

/* {{{ Constructor. Throws an Exception in case the given extension does not exist */
ZEND_METHOD(ReflectionExtension, __construct)
{
Expand Down
4 changes: 4 additions & 0 deletions ext/reflection/php_reflection.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@ class ReflectionProperty implements Reflector
public const int IS_PROTECTED_SET = UNKNOWN;
/** @cvalue ZEND_ACC_PRIVATE_SET */
public const int IS_PRIVATE_SET = UNKNOWN;
/** @cvalue ZEND_ACC_FINAL */
public const int IS_FINAL = UNKNOWN;

public string $name;
public string $class;
Expand Down Expand Up @@ -565,6 +567,8 @@ public function getHooks(): array {}
public function hasHook(PropertyHookType $type): bool {}

public function getHook(PropertyHookType $type): ?ReflectionMethod {}

public function isFinal(): bool {}
}

/** @not-serializable */
Expand Down
12 changes: 11 additions & 1 deletion ext/reflection/php_reflection_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class C {
static public $a4;
static protected $a5;
static private $a6;
public final $a7;
public static final $a8;
}

class D extends C {
Expand All @@ -21,7 +23,7 @@ class D extends C {
static private $a6;
}

for ($i = 1;$i <= 6;$i++) {
for ($i = 1;$i <= 8;$i++) {
$rp = new ReflectionProperty("C", "a$i");
echo "C::a$i: ";
var_dump($rp->getModifiers());
Expand All @@ -44,3 +46,7 @@ C::a5: int(18)
D::a5: int(18)
C::a6: int(20)
D::a6: int(20)
C::a7: int(33)
D::a7: int(33)
C::a8: int(49)
D::a8: int(49)
32 changes: 32 additions & 0 deletions ext/reflection/tests/ReflectionProperty_isFinal.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--TEST--
ReflectionProperty::isFinal()
--FILE--
<?php

class C {
public $p1;
public final $p2;
public $p3 { get => 42; }
public final $p4 { get => 42; }
public protected(set) mixed $p5;
public protected(set) final mixed $p6;
public private(set) mixed $p7;
public private(set) final mixed $p8;
}

$rc = new ReflectionClass(C::class);
foreach ($rc->getProperties() as $rp) {
echo $rp->getName(), ": ";
var_dump($rp->isFinal());
}

?>
--EXPECT--
p1: bool(false)
p2: bool(true)
p3: bool(false)
p4: bool(true)
p5: bool(false)
p6: bool(true)
p7: bool(true)
p8: bool(true)
Loading