Skip to content

Commit 76e5d82

Browse files
DanielEScherzeriluuu1994
authored andcommitted
Fix phpGH-16162: No ReflectionProperty::IS_VIRTUAL
Closes phpGH-16166
1 parent 7f1fd06 commit 76e5d82

7 files changed

+67
-4
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ PHP NEWS
9292
and ReflectionFunction::inNamespace() for closures is incorrect). (timwolla)
9393
. Fixed bug GH-16187 (Assertion failure in ext/reflection/php_reflection.c).
9494
(DanielEScherzer)
95+
. Fixed bug GH-16162 (No ReflectionProperty::IS_VIRTUAL) (DanielEScherzer)
9596

9697
- SAPI:
9798
. Fixed bug GHSA-9pqp-7h25-4f32 (Erroneous parsing of multipart form data).

ext/reflection/php_reflection.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,6 +1595,9 @@ ZEND_METHOD(Reflection, getModifierNames)
15951595
if (modifiers & ZEND_ACC_FINAL) {
15961596
add_next_index_stringl(return_value, "final", sizeof("final")-1);
15971597
}
1598+
if (modifiers & ZEND_ACC_VIRTUAL) {
1599+
add_next_index_stringl(return_value, "virtual", sizeof("virtual")-1);
1600+
}
15981601

15991602
/* These are mutually exclusive */
16001603
switch (modifiers & ZEND_ACC_PPP_MASK) {

ext/reflection/php_reflection.stub.php

Lines changed: 2 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_VIRTUAL */
474+
public const int IS_VIRTUAL = UNKNOWN;
473475
/** @cvalue ZEND_ACC_FINAL */
474476
public const int IS_FINAL = UNKNOWN;
475477

ext/reflection/php_reflection_arginfo.h

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

ext/reflection/tests/ReflectionClass_getProperties_003.phpt

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ class C {
1414
static public $pubs2;
1515
static private $privs1;
1616
static private $privs2;
17+
public $hookNoVirt { set { $this->hookNoVirt = strtoupper($value); } }
18+
public $hookVirt { get { return 42; } }
1719
}
1820

1921
$rc = new ReflectionClass("C");
2022
$StaticFlag = ReflectionProperty::IS_STATIC;
2123
$pubFlag = ReflectionProperty::IS_PUBLIC;
2224
$privFlag = ReflectionProperty::IS_PRIVATE;
25+
$virtFlag = ReflectionProperty::IS_VIRTUAL;
2326

2427
echo "No properties:";
2528
var_dump($rc->getProperties(0));
@@ -35,11 +38,14 @@ var_dump($rc->getProperties($StaticFlag | $pubFlag));
3538

3639
echo "Private or static properties:";
3740
var_dump($rc->getProperties($StaticFlag | $privFlag));
41+
42+
echo "Virtual properties:";
43+
var_dump($rc->getProperties($virtFlag));
3844
?>
3945
--EXPECTF--
4046
No properties:array(0) {
4147
}
42-
Public properties:array(4) {
48+
Public properties:array(6) {
4349
[0]=>
4450
object(ReflectionProperty)#%d (2) {
4551
["name"]=>
@@ -68,6 +74,20 @@ Public properties:array(4) {
6874
["class"]=>
6975
string(1) "C"
7076
}
77+
[4]=>
78+
object(ReflectionProperty)#%d (2) {
79+
["name"]=>
80+
string(10) "hookNoVirt"
81+
["class"]=>
82+
string(1) "C"
83+
}
84+
[5]=>
85+
object(ReflectionProperty)#%d (2) {
86+
["name"]=>
87+
string(8) "hookVirt"
88+
["class"]=>
89+
string(1) "C"
90+
}
7191
}
7292
Private properties:array(4) {
7393
[0]=>
@@ -99,7 +119,7 @@ Private properties:array(4) {
99119
string(1) "C"
100120
}
101121
}
102-
Public or static properties:array(6) {
122+
Public or static properties:array(8) {
103123
[0]=>
104124
object(ReflectionProperty)#%d (2) {
105125
["name"]=>
@@ -142,6 +162,20 @@ Public or static properties:array(6) {
142162
["class"]=>
143163
string(1) "C"
144164
}
165+
[6]=>
166+
object(ReflectionProperty)#%d (2) {
167+
["name"]=>
168+
string(10) "hookNoVirt"
169+
["class"]=>
170+
string(1) "C"
171+
}
172+
[7]=>
173+
object(ReflectionProperty)#%d (2) {
174+
["name"]=>
175+
string(8) "hookVirt"
176+
["class"]=>
177+
string(1) "C"
178+
}
145179
}
146180
Private or static properties:array(6) {
147181
[0]=>
@@ -187,3 +221,12 @@ Private or static properties:array(6) {
187221
string(1) "C"
188222
}
189223
}
224+
Virtual properties:array(1) {
225+
[0]=>
226+
object(ReflectionProperty)#%d (2) {
227+
["name"]=>
228+
string(8) "hookVirt"
229+
["class"]=>
230+
string(1) "C"
231+
}
232+
}

ext/reflection/tests/ReflectionProperty_getModifiers_basic.phpt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class C {
1212
static private $a6;
1313
public final $a7;
1414
public static final $a8;
15+
public $a9 { set { $this->a9 = strtoupper($value); } }
16+
public $a10 { get { return 42; } }
1517
}
1618

1719
class D extends C {
@@ -23,7 +25,7 @@ class D extends C {
2325
static private $a6;
2426
}
2527

26-
for ($i = 1;$i <= 8;$i++) {
28+
for ($i = 1;$i <= 10;$i++) {
2729
$rp = new ReflectionProperty("C", "a$i");
2830
echo "C::a$i: ";
2931
var_dump($rp->getModifiers());
@@ -50,3 +52,7 @@ C::a7: int(33)
5052
D::a7: int(33)
5153
C::a8: int(49)
5254
D::a8: int(49)
55+
C::a9: int(1)
56+
D::a9: int(1)
57+
C::a10: int(513)
58+
D::a10: int(513)

ext/reflection/tests/Reflection_getModifierNames_001.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ printModifiers(ReflectionClass::IS_EXPLICIT_ABSTRACT);
1414
printModifiers(ReflectionMethod::IS_ABSTRACT | ReflectionMethod::IS_FINAL);
1515
printModifiers(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_STATIC | ReflectionProperty::IS_READONLY);
1616
printModifiers(ReflectionClass::IS_READONLY);
17+
printModifiers(ReflectionProperty::IS_VIRTUAL);
1718
?>
1819
--EXPECT--
1920
private
@@ -23,3 +24,4 @@ abstract
2324
abstract,final
2425
public,static,readonly
2526
readonly
27+
virtual

0 commit comments

Comments
 (0)