Skip to content

Commit 6ea33b8

Browse files
committed
PHP 8.2 | File::getMemberProperties(): allow for true in types
As of PHP 8.2, `true`, `false` and `null` will be allowed as stand-alone types. `true` can now also be used in union types (was already allowed for `false` and `null`). The `true` and the `false` types are allowed to be nullable, the `null` type is not (but that's not the concern of this method). Also see: https://3v4l.org/ZpfID This commit adjusts the `File::getMemberProperties()` method to take `true` into account. `false` and `null` were already handled due to these previously already being allowed in union types. Includes unit tests. Includes minor touch up of some pre-existing tests. Refs: * https://wiki.php.net/rfc/null-false-standalone-types * https://wiki.php.net/rfc/true-type
1 parent 8af4ace commit 6ea33b8

File tree

3 files changed

+69
-4
lines changed

3 files changed

+69
-4
lines changed

src/Files/File.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,6 +1908,7 @@ public function getMemberProperties($stackPtr)
19081908
T_SELF => T_SELF,
19091909
T_PARENT => T_PARENT,
19101910
T_FALSE => T_FALSE,
1911+
T_TRUE => T_TRUE,
19111912
T_NULL => T_NULL,
19121913
T_NAMESPACE => T_NAMESPACE,
19131914
T_NS_SEPARATOR => T_NS_SEPARATOR,

tests/Core/File/GetMemberPropertiesTest.inc

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,11 @@ $anon = class() {
217217
public ?int|float $unionTypesNullable;
218218

219219
/* testPHP8PseudoTypeNull */
220-
// Intentional fatal error - null pseudotype is only allowed in union types, but that's not the concern of the method.
220+
// PHP 8.0 - 8.1: Intentional fatal error - null pseudotype is only allowed in union types, but that's not the concern of the method.
221221
public null $pseudoTypeNull;
222222

223223
/* testPHP8PseudoTypeFalse */
224-
// Intentional fatal error - false pseudotype is only allowed in union types, but that's not the concern of the method.
224+
// PHP 8.0 - 8.1: Intentional fatal error - false pseudotype is only allowed in union types, but that's not the concern of the method.
225225
public false $pseudoTypeFalse;
226226

227227
/* testPHP8PseudoTypeFalseAndBool */
@@ -298,7 +298,22 @@ $anon = class() {
298298
// Intentional fatal error - types which are not allowed for intersection type, but that's not the concern of the method.
299299
public int&string $illegalIntersectionType;
300300

301-
/* testPHP81NulltableIntersectionType */
301+
/* testPHP81NullableIntersectionType */
302302
// Intentional fatal error - nullability is not allowed with intersection type, but that's not the concern of the method.
303303
public ?Foo&Bar $nullableIntersectionType;
304304
};
305+
306+
$anon = class() {
307+
/* testPHP82PseudoTypeTrue */
308+
public true $pseudoTypeTrue;
309+
310+
/* testPHP82NullablePseudoTypeTrue */
311+
static protected ?true $pseudoTypeNullableTrue;
312+
313+
/* testPHP82PseudoTypeTrueInUnion */
314+
private int|string|true $pseudoTypeTrueInUnion;
315+
316+
/* testPHP82PseudoTypeFalseAndTrue */
317+
// Intentional fatal error - Type contains both true and false, bool should be used instead, but that's not the concern of the method.
318+
readonly true|FALSE $pseudoTypeFalseAndTrue;
319+
};

tests/Core/File/GetMemberPropertiesTest.php

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,7 @@ public function dataGetMemberProperties()
764764
'scope' => 'public',
765765
'scope_specified' => true,
766766
'is_static' => false,
767+
'is_readonly' => false,
767768
'type' => 'Foo&Bar',
768769
'nullable_type' => false,
769770
],
@@ -774,6 +775,7 @@ public function dataGetMemberProperties()
774775
'scope' => 'public',
775776
'scope_specified' => true,
776777
'is_static' => false,
778+
'is_readonly' => false,
777779
'type' => 'Foo&Bar&Baz',
778780
'nullable_type' => false,
779781
],
@@ -784,20 +786,67 @@ public function dataGetMemberProperties()
784786
'scope' => 'public',
785787
'scope_specified' => true,
786788
'is_static' => false,
789+
'is_readonly' => false,
787790
'type' => 'int&string',
788791
'nullable_type' => false,
789792
],
790793
],
791794
[
792-
'/* testPHP81NulltableIntersectionType */',
795+
'/* testPHP81NullableIntersectionType */',
793796
[
794797
'scope' => 'public',
795798
'scope_specified' => true,
796799
'is_static' => false,
800+
'is_readonly' => false,
797801
'type' => '?Foo&Bar',
798802
'nullable_type' => true,
799803
],
800804
],
805+
[
806+
'/* testPHP82PseudoTypeTrue */',
807+
[
808+
'scope' => 'public',
809+
'scope_specified' => true,
810+
'is_static' => false,
811+
'is_readonly' => false,
812+
'type' => 'true',
813+
'nullable_type' => false,
814+
],
815+
],
816+
[
817+
'/* testPHP82NullablePseudoTypeTrue */',
818+
[
819+
'scope' => 'protected',
820+
'scope_specified' => true,
821+
'is_static' => true,
822+
'is_readonly' => false,
823+
'type' => '?true',
824+
'nullable_type' => true,
825+
],
826+
],
827+
[
828+
'/* testPHP82PseudoTypeTrueInUnion */',
829+
[
830+
'scope' => 'private',
831+
'scope_specified' => true,
832+
'is_static' => false,
833+
'is_readonly' => false,
834+
'type' => 'int|string|true',
835+
'nullable_type' => false,
836+
],
837+
],
838+
[
839+
'/* testPHP82PseudoTypeFalseAndTrue */',
840+
[
841+
'scope' => 'public',
842+
'scope_specified' => false,
843+
'is_static' => false,
844+
'is_readonly' => true,
845+
'type' => 'true|FALSE',
846+
'nullable_type' => false,
847+
],
848+
],
849+
801850
];
802851

803852
}//end dataGetMemberProperties()

0 commit comments

Comments
 (0)