File tree Expand file tree Collapse file tree 3 files changed +21
-2
lines changed
test/php/lang/reflection/unittest Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Original file line number Diff line number Diff 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 ,
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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 ' );
You can’t perform that action at this time.
0 commit comments