Skip to content

Commit 2fce0bb

Browse files
committed
Implement ReflectionProperty::isFinal()
Closes GH-15919
1 parent 1ce07b0 commit 2fce0bb

6 files changed

+61
-3
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ PHP NEWS
1919

2020
- Reflection:
2121
. Add missing ReflectionProperty::hasHook[s]() methods. (ilutov)
22+
. Add missing ReflectionProperty::isFinal() method. (ilutov)
2223

2324
- SimpleXML:
2425
. Fixed bug GH-15837 (Segmentation fault in ext/simplexml/simplexml.c).

ext/reflection/php_reflection.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5960,7 +5960,7 @@ ZEND_METHOD(ReflectionProperty, getModifiers)
59605960
{
59615961
reflection_object *intern;
59625962
property_reference *ref;
5963-
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;
5963+
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;
59645964

59655965
if (zend_parse_parameters_none() == FAILURE) {
59665966
RETURN_THROWS();
@@ -6604,6 +6604,11 @@ ZEND_METHOD(ReflectionProperty, getHook)
66046604
reflection_method_factory(hook->common.scope, hook, NULL, return_value);
66056605
}
66066606

6607+
ZEND_METHOD(ReflectionProperty, isFinal)
6608+
{
6609+
_property_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_FINAL);
6610+
}
6611+
66076612
/* {{{ Constructor. Throws an Exception in case the given extension does not exist */
66086613
ZEND_METHOD(ReflectionExtension, __construct)
66096614
{

ext/reflection/php_reflection.stub.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,8 @@ class ReflectionProperty implements Reflector
470470
public const int IS_PROTECTED_SET = UNKNOWN;
471471
/** @cvalue ZEND_ACC_PRIVATE_SET */
472472
public const int IS_PRIVATE_SET = UNKNOWN;
473+
/** @cvalue ZEND_ACC_FINAL */
474+
public const int IS_FINAL = UNKNOWN;
473475

474476
public string $name;
475477
public string $class;
@@ -565,6 +567,8 @@ public function getHooks(): array {}
565567
public function hasHook(PropertyHookType $type): bool {}
566568

567569
public function getHook(PropertyHookType $type): ?ReflectionMethod {}
570+
571+
public function isFinal(): bool {}
568572
}
569573

570574
/** @not-serializable */

ext/reflection/php_reflection_arginfo.h

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/reflection/tests/ReflectionProperty_getModifiers_basic.phpt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class C {
1010
static public $a4;
1111
static protected $a5;
1212
static private $a6;
13+
public final $a7;
14+
public static final $a8;
1315
}
1416

1517
class D extends C {
@@ -21,7 +23,7 @@ class D extends C {
2123
static private $a6;
2224
}
2325

24-
for ($i = 1;$i <= 6;$i++) {
26+
for ($i = 1;$i <= 8;$i++) {
2527
$rp = new ReflectionProperty("C", "a$i");
2628
echo "C::a$i: ";
2729
var_dump($rp->getModifiers());
@@ -44,3 +46,7 @@ C::a5: int(18)
4446
D::a5: int(18)
4547
C::a6: int(20)
4648
D::a6: int(20)
49+
C::a7: int(33)
50+
D::a7: int(33)
51+
C::a8: int(49)
52+
D::a8: int(49)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
ReflectionProperty::isFinal()
3+
--FILE--
4+
<?php
5+
6+
class C {
7+
public $p1;
8+
public final $p2;
9+
public $p3 { get => 42; }
10+
public final $p4 { get => 42; }
11+
public protected(set) mixed $p5;
12+
public protected(set) final mixed $p6;
13+
public private(set) mixed $p7;
14+
public private(set) final mixed $p8;
15+
}
16+
17+
$rc = new ReflectionClass(C::class);
18+
foreach ($rc->getProperties() as $rp) {
19+
echo $rp->getName(), ": ";
20+
var_dump($rp->isFinal());
21+
}
22+
23+
?>
24+
--EXPECT--
25+
p1: bool(false)
26+
p2: bool(true)
27+
p3: bool(false)
28+
p4: bool(true)
29+
p5: bool(false)
30+
p6: bool(true)
31+
p7: bool(true)
32+
p8: bool(true)

0 commit comments

Comments
 (0)