|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Bug13042 { |
| 4 | + |
| 5 | + trait SomeTrait |
| 6 | + { |
| 7 | + |
| 8 | + /** @internal don't use it directly */ |
| 9 | + private ?string $text = null; |
| 10 | + |
| 11 | + /** @internal */ |
| 12 | + private static ?string $staticText = null; |
| 13 | + |
| 14 | + /** @internal */ |
| 15 | + private function internalMethod(): void |
| 16 | + { |
| 17 | + } |
| 18 | + |
| 19 | + /** @internal */ |
| 20 | + private static function internalStaticMethod(): void |
| 21 | + { |
| 22 | + } |
| 23 | + |
| 24 | + public function setText(string $text): void |
| 25 | + { |
| 26 | + $this->text = $text; |
| 27 | + self::$staticText = $text; |
| 28 | + $this->internalMethod(); |
| 29 | + self::internalStaticMethod(); |
| 30 | + } |
| 31 | + |
| 32 | + } |
| 33 | + |
| 34 | + class HelloWorld |
| 35 | + { |
| 36 | + |
| 37 | + public function sayHello(): object |
| 38 | + { |
| 39 | + return new class { |
| 40 | + |
| 41 | + use SomeTrait; |
| 42 | + |
| 43 | + /** @internal */ |
| 44 | + public $ownProperty; |
| 45 | + |
| 46 | + /** @internal */ |
| 47 | + public static $ownStaticProperty; |
| 48 | + |
| 49 | + /** @internal */ |
| 50 | + public const OWN_CONSTANT = 'x'; |
| 51 | + |
| 52 | + /** @internal */ |
| 53 | + public function ownMethod(): void |
| 54 | + { |
| 55 | + } |
| 56 | + |
| 57 | + /** @internal */ |
| 58 | + public static function ownStaticMethod(): void |
| 59 | + { |
| 60 | + } |
| 61 | + |
| 62 | + public function doFoo(): void |
| 63 | + { |
| 64 | + $this->ownProperty; |
| 65 | + self::$ownStaticProperty; |
| 66 | + self::OWN_CONSTANT; |
| 67 | + $this->ownMethod(); |
| 68 | + self::ownStaticMethod(); |
| 69 | + } |
| 70 | + |
| 71 | + }; |
| 72 | + } |
| 73 | + |
| 74 | + public function fromTheOutside(): void |
| 75 | + { |
| 76 | + $foo = new class { |
| 77 | + |
| 78 | + /** @internal */ |
| 79 | + public $internal; |
| 80 | + |
| 81 | + /** @internal */ |
| 82 | + public static $internalStatic; |
| 83 | + |
| 84 | + /** @internal */ |
| 85 | + const INTERNAL = 'x'; |
| 86 | + |
| 87 | + /** @internal */ |
| 88 | + public function doInternal(): void |
| 89 | + { |
| 90 | + } |
| 91 | + |
| 92 | + /** @internal */ |
| 93 | + public static function doInternalStatic(): void |
| 94 | + { |
| 95 | + } |
| 96 | + |
| 97 | + }; |
| 98 | + |
| 99 | + $foo->internal; |
| 100 | + $foo::$internalStatic; |
| 101 | + $foo::INTERNAL; |
| 102 | + $foo->doInternal(); |
| 103 | + $foo::doInternalStatic(); |
| 104 | + } |
| 105 | + |
| 106 | + } |
| 107 | + |
| 108 | + class Foo |
| 109 | + { |
| 110 | + |
| 111 | + /** @internal */ |
| 112 | + public $internal; |
| 113 | + |
| 114 | + /** @internal */ |
| 115 | + public static $internalStatic; |
| 116 | + |
| 117 | + /** @internal */ |
| 118 | + const INTERNAL = 'x'; |
| 119 | + |
| 120 | + /** @internal */ |
| 121 | + public function doInternal(): void |
| 122 | + { |
| 123 | + } |
| 124 | + |
| 125 | + /** @internal */ |
| 126 | + public static function doInternalStatic(): void |
| 127 | + { |
| 128 | + } |
| 129 | + |
| 130 | + } |
| 131 | + |
| 132 | +} |
| 133 | + |
| 134 | +namespace Bug13042Other { |
| 135 | + |
| 136 | + function (): object { |
| 137 | + return new class { |
| 138 | + |
| 139 | + public function doFoo(\Bug13042\Foo $foo): void |
| 140 | + { |
| 141 | + $foo->internal; |
| 142 | + $foo::$internalStatic; |
| 143 | + $foo::INTERNAL; |
| 144 | + $foo->doInternal(); |
| 145 | + $foo::doInternalStatic(); |
| 146 | + } |
| 147 | + |
| 148 | + }; |
| 149 | + }; |
| 150 | + |
| 151 | +} |
| 152 | + |
| 153 | +namespace Bug13042Inheritance { |
| 154 | + |
| 155 | + function (): object { |
| 156 | + return new class extends \Bug13042\Foo { |
| 157 | + |
| 158 | + public function doFoo(): void |
| 159 | + { |
| 160 | + $this->internal; |
| 161 | + self::$internalStatic; |
| 162 | + self::INTERNAL; |
| 163 | + $this->doInternal(); |
| 164 | + self::doInternalStatic(); |
| 165 | + } |
| 166 | + |
| 167 | + }; |
| 168 | + }; |
| 169 | + |
| 170 | + // A named subclass gets the very same exemptions: the static access rules re-ask |
| 171 | + // the extension with the referenced class instead of the declaring one, so only |
| 172 | + // the instance accesses below are reported. The anonymous subclass above must not |
| 173 | + // be reported any more strictly than this one. |
| 174 | + class NamedSubclass extends \Bug13042\Foo |
| 175 | + { |
| 176 | + |
| 177 | + public function doFoo(): void |
| 178 | + { |
| 179 | + $this->internal; |
| 180 | + self::$internalStatic; |
| 181 | + self::INTERNAL; |
| 182 | + $this->doInternal(); |
| 183 | + self::doInternalStatic(); |
| 184 | + } |
| 185 | + |
| 186 | + } |
| 187 | + |
| 188 | +} |
0 commit comments