Skip to content

Fix GH-16162: No ReflectionProperty::IS_VIRTUAL #16166

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
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
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ PHP NEWS
and ReflectionFunction::inNamespace() for closures is incorrect). (timwolla)
. Fixed bug GH-16187 (Assertion failure in ext/reflection/php_reflection.c).
(DanielEScherzer)
. Fixed bug GH-16162 (No ReflectionProperty::IS_VIRTUAL) (DanielEScherzer)

- SAPI:
. Fixed bug GHSA-9pqp-7h25-4f32 (Erroneous parsing of multipart form data).
Expand Down
3 changes: 3 additions & 0 deletions ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,9 @@ ZEND_METHOD(Reflection, getModifierNames)
if (modifiers & ZEND_ACC_FINAL) {
add_next_index_stringl(return_value, "final", sizeof("final")-1);
}
if (modifiers & ZEND_ACC_VIRTUAL) {
add_next_index_stringl(return_value, "virtual", sizeof("virtual")-1);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note: This is not a great function, as it provides no way of disambiguating flags. We just got lucky again that ZEND_ACC_VIRTUAL doesn't clash with any other flags returned from any of the getModifiers() methods. We should probably deprecated it and replace it with class-specific counterparts, e.g. ReflectionProperty::getModifierNames().


/* These are mutually exclusive */
switch (modifiers & ZEND_ACC_PPP_MASK) {
Expand Down
2 changes: 2 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_VIRTUAL */
public const int IS_VIRTUAL = UNKNOWN;
/** @cvalue ZEND_ACC_FINAL */
public const int IS_FINAL = UNKNOWN;

Expand Down
8 changes: 7 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.

47 changes: 45 additions & 2 deletions ext/reflection/tests/ReflectionClass_getProperties_003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ class C {
static public $pubs2;
static private $privs1;
static private $privs2;
public $hookNoVirt { set { $this->hookNoVirt = strtoupper( $value ); } }
public $hookVirt { get { return 42; } }
}

$rc = new ReflectionClass("C");
$StaticFlag = ReflectionProperty::IS_STATIC;
$pubFlag = ReflectionProperty::IS_PUBLIC;
$privFlag = ReflectionProperty::IS_PRIVATE;
$virtFlag = ReflectionProperty::IS_VIRTUAL;

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

echo "Private or static properties:";
var_dump($rc->getProperties($StaticFlag | $privFlag));

echo "Virtual properties:";
var_dump($rc->getProperties($virtFlag));
?>
--EXPECTF--
No properties:array(0) {
}
Public properties:array(4) {
Public properties:array(6) {
[0]=>
object(ReflectionProperty)#%d (2) {
["name"]=>
Expand Down Expand Up @@ -68,6 +74,20 @@ Public properties:array(4) {
["class"]=>
string(1) "C"
}
[4]=>
object(ReflectionProperty)#%d (2) {
["name"]=>
string(10) "hookNoVirt"
["class"]=>
string(1) "C"
}
[5]=>
object(ReflectionProperty)#%d (2) {
["name"]=>
string(8) "hookVirt"
["class"]=>
string(1) "C"
}
}
Private properties:array(4) {
[0]=>
Expand Down Expand Up @@ -99,7 +119,7 @@ Private properties:array(4) {
string(1) "C"
}
}
Public or static properties:array(6) {
Public or static properties:array(8) {
[0]=>
object(ReflectionProperty)#%d (2) {
["name"]=>
Expand Down Expand Up @@ -142,6 +162,20 @@ Public or static properties:array(6) {
["class"]=>
string(1) "C"
}
[6]=>
object(ReflectionProperty)#%d (2) {
["name"]=>
string(10) "hookNoVirt"
["class"]=>
string(1) "C"
}
[7]=>
object(ReflectionProperty)#%d (2) {
["name"]=>
string(8) "hookVirt"
["class"]=>
string(1) "C"
}
}
Private or static properties:array(6) {
[0]=>
Expand Down Expand Up @@ -187,3 +221,12 @@ Private or static properties:array(6) {
string(1) "C"
}
}
Virtual properties:array(1) {
[0]=>
object(ReflectionProperty)#%d (2) {
["name"]=>
string(8) "hookVirt"
["class"]=>
string(1) "C"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class C {
static private $a6;
public final $a7;
public static final $a8;
public $a9 { set { $this->a9 = strtoupper( $value ); } }
public $a10 { get { return 42; } }
}

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

for ($i = 1;$i <= 8;$i++) {
for ($i = 1;$i <= 10;$i++) {
$rp = new ReflectionProperty("C", "a$i");
echo "C::a$i: ";
var_dump($rp->getModifiers());
Expand All @@ -50,3 +52,7 @@ C::a7: int(33)
D::a7: int(33)
C::a8: int(49)
D::a8: int(49)
C::a9: int(1)
D::a9: int(1)
C::a10: int(513)
D::a10: int(513)
2 changes: 2 additions & 0 deletions ext/reflection/tests/Reflection_getModifierNames_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ printModifiers(ReflectionClass::IS_EXPLICIT_ABSTRACT);
printModifiers(ReflectionMethod::IS_ABSTRACT | ReflectionMethod::IS_FINAL);
printModifiers(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_STATIC | ReflectionProperty::IS_READONLY);
printModifiers(ReflectionClass::IS_READONLY);
printModifiers(ReflectionProperty::IS_VIRTUAL);
?>
--EXPECT--
private
Expand All @@ -23,3 +24,4 @@ abstract
abstract,final
public,static,readonly
readonly
virtual