File tree 8 files changed +18
-3
lines changed
8 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -127,6 +127,8 @@ The file documents changes to the PHP_CodeSniffer project.
127
127
- Thanks to Dan Wallis (@fredden ) for the patch
128
128
- Fixed bug #3816 : PSR12/FileHeader: bug fix - false positives on PHP 8.2+ readonly classes
129
129
- Thanks to Juliette Reinders Folmer (@jrfnl ) for the patch
130
+ - Fixed bug #3867 : Tokenizer/PHP: union type and intersection type operators were not correctly tokenized for static properties without explicit visibility
131
+ - Thanks to Juliette Reinders Folmer (@jrfnl ) for the patch
130
132
- Fixed bug #3877 : Filter names can be case-sensitive. The -h help text will now display the correct case for the available filters
131
133
- Thanks to @simonsan for the patch
132
134
- Fixed bug #3906 : Tokenizer/CSS: fixed a bug related to the unsupported slash comment syntax
Original file line number Diff line number Diff line change @@ -2998,6 +2998,10 @@ protected function processAdditional()
2998
2998
continue ;
2999
2999
}
3000
3000
3001
+ if ($ suspectedType === 'property or parameter ' ) {
3002
+ unset($ allowed [\T_STATIC ]);
3003
+ }
3004
+
3001
3005
$ typeTokenCount = 0 ;
3002
3006
$ typeOperators = [$ i ];
3003
3007
$ confirmed = false ;
@@ -3030,6 +3034,7 @@ protected function processAdditional()
3030
3034
if ($ suspectedType === 'property or parameter '
3031
3035
&& (isset (Util \Tokens::$ scopeModifiers [$ this ->tokens [$ x ]['code ' ]]) === true
3032
3036
|| $ this ->tokens [$ x ]['code ' ] === T_VAR
3037
+ || $ this ->tokens [$ x ]['code ' ] === T_STATIC
3033
3038
|| $ this ->tokens [$ x ]['code ' ] === T_READONLY )
3034
3039
) {
3035
3040
// This will also confirm constructor property promotion parameters, but that's fine.
Original file line number Diff line number Diff line change @@ -210,7 +210,8 @@ $anon = class() {
210
210
211
211
/* testPHP8UnionTypesIllegalTypes */
212
212
// Intentional fatal error - types which are not allowed for properties, but that's not the concern of the method.
213
- public callable|static |void $ unionTypesIllegalTypes;
213
+ // Note: static is also not allowed as a type, but using static for a property type is not supported by the tokenizer.
214
+ public callable|void $ unionTypesIllegalTypes ;
214
215
215
216
/* testPHP8UnionTypesNullable */
216
217
// Intentional fatal error - nullability is not allowed with union types, but that's not the concern of the method.
Original file line number Diff line number Diff line change @@ -587,8 +587,7 @@ public function dataGetMemberProperties()
587
587
'scope_specified ' => true ,
588
588
'is_static ' => false ,
589
589
'is_readonly ' => false ,
590
- // Missing static, but that's OK as not an allowed syntax.
591
- 'type ' => 'callable||void ' ,
590
+ 'type ' => 'callable|void ' ,
592
591
'nullable_type ' => false ,
593
592
],
594
593
],
Original file line number Diff line number Diff line change @@ -48,6 +48,9 @@ class TypeUnion
48
48
/* testTypeUnionPropertyWithOnlyReadOnlyKeyword */
49
49
readonly string |null $ nullableString ;
50
50
51
+ /* testTypeUnionPropertyWithOnlyStaticKeyword */
52
+ static Foo |Bar $ obj ;
53
+
51
54
public function paramTypes (
52
55
/* testTypeUnionParam1 */
53
56
int |float $ paramA /* testBitwiseOrParamDefaultValue */ = CONSTANT_A | CONSTANT_B ,
Original file line number Diff line number Diff line change @@ -110,6 +110,7 @@ public function dataTypeUnion()
110
110
['/* testTypeUnionPropertyWithStaticAndReadOnlyKeywords */ ' ],
111
111
['/* testTypeUnionPropertyWithVarAndReadOnlyKeywords */ ' ],
112
112
['/* testTypeUnionPropertyWithOnlyReadOnlyKeyword */ ' ],
113
+ ['/* testTypeUnionPropertyWithOnlyStaticKeyword */ ' ],
113
114
['/* testTypeUnionParam1 */ ' ],
114
115
['/* testTypeUnionParam2 */ ' ],
115
116
['/* testTypeUnionParam3 */ ' ],
Original file line number Diff line number Diff line change @@ -36,6 +36,9 @@ class TypeIntersection
36
36
/* testTypeIntersectionPropertyWithReadOnlyKeyword */
37
37
protected readonly Foo &Bar $ fooBar ;
38
38
39
+ /* testTypeIntersectionPropertyWithStaticKeyword */
40
+ static Foo &Bar $ obj ;
41
+
39
42
public function paramTypes (
40
43
/* testTypeIntersectionParam1 */
41
44
Foo &Bar $ paramA /* testBitwiseAndParamDefaultValue */ = CONSTANT_A & CONSTANT_B ,
Original file line number Diff line number Diff line change @@ -109,6 +109,7 @@ public function dataTypeIntersection()
109
109
['/* testTypeIntersectionPropertyPartiallyQualified */ ' ],
110
110
['/* testTypeIntersectionPropertyFullyQualified */ ' ],
111
111
['/* testTypeIntersectionPropertyWithReadOnlyKeyword */ ' ],
112
+ ['/* testTypeIntersectionPropertyWithStaticKeyword */ ' ],
112
113
['/* testTypeIntersectionParam1 */ ' ],
113
114
['/* testTypeIntersectionParam2 */ ' ],
114
115
['/* testTypeIntersectionParam3 */ ' ],
You can’t perform that action at this time.
0 commit comments