Skip to content

Commit b0122e4

Browse files
committed
Mask out all other modifiers when modifiers([get|set]) is called
1 parent 5813384 commit b0122e4

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/main/php/lang/reflection/Modifiers.class.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class Modifiers implements Value {
2020
const IS_PRIVATE_SET = 0x1000;
2121
const IS_NATIVE = 0x10000;
2222

23+
const GET_MASK = 0x0007; // PUBLIC | PROTECTED | PRIVATE
24+
const SET_MASK = 0x1c00; // PUBLIC_SET | PROTECTED_SET | PRIVATE_SET
25+
2326
private static $names= [
2427
'public' => self::IS_PUBLIC,
2528
'protected' => self::IS_PROTECTED,

src/main/php/lang/reflection/Property.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ public function modifiers($hook= null) {
5555
$bits= $this->reflect->getModifiers();
5656
switch ($hook) {
5757
case null: return new Modifiers($bits);
58-
case 'get': return new Modifiers($bits & ~0x1c00);
59-
case 'set': return new Modifiers($set[$bits & 0x1c00] ?? $bits);
58+
case 'get': return new Modifiers(($bits & ~Modifiers::SET_MASK) & Modifiers::GET_MASK);
59+
case 'set': return new Modifiers($set[$bits & Modifiers::SET_MASK] ?? $bits & Modifiers::GET_MASK);
6060
default: throw new IllegalArgumentException('Unknown hook '.$hook);
6161
}
6262
}

src/test/php/lang/reflection/unittest/PropertiesTest.class.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,22 @@ public function set_modifiers($modifier) {
4949
);
5050
}
5151

52+
#[Test]
53+
public function get_modifiers_erases_static() {
54+
Assert::equals(
55+
new Modifiers('public'),
56+
$this->declare('{ public static int $fixture; }')->property('fixture')->modifiers('get')
57+
);
58+
}
59+
60+
#[Test]
61+
public function set_modifiers_erases_static() {
62+
Assert::equals(
63+
new Modifiers('public'),
64+
$this->declare('{ public static int $fixture; }')->property('fixture')->modifiers('set')
65+
);
66+
}
67+
5268
#[Test, Expect(IllegalArgumentException::class)]
5369
public function modifiers_unknown_hook() {
5470
$this->declare('{ private $fixture; }')->property('fixture')->modifiers('@unknown');

0 commit comments

Comments
 (0)