Skip to content

Commit 6e307f5

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 3aa8682 commit 6e307f5

File tree

3 files changed

+65
-4
lines changed

3 files changed

+65
-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: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ public function dataGetMemberProperties()
795795
],
796796
],
797797
[
798-
'/* testPHP81NulltableIntersectionType */',
798+
'/* testPHP81NullableIntersectionType */',
799799
[
800800
'scope' => 'public',
801801
'scope_specified' => true,
@@ -805,6 +805,51 @@ public function dataGetMemberProperties()
805805
'nullable_type' => true,
806806
],
807807
],
808+
[
809+
'/* testPHP82PseudoTypeTrue */',
810+
[
811+
'scope' => 'public',
812+
'scope_specified' => true,
813+
'is_static' => false,
814+
'is_readonly' => false,
815+
'type' => 'true',
816+
'nullable_type' => false,
817+
],
818+
],
819+
[
820+
'/* testPHP82NullablePseudoTypeTrue */',
821+
[
822+
'scope' => 'protected',
823+
'scope_specified' => true,
824+
'is_static' => true,
825+
'is_readonly' => false,
826+
'type' => '?true',
827+
'nullable_type' => true,
828+
],
829+
],
830+
[
831+
'/* testPHP82PseudoTypeTrueInUnion */',
832+
[
833+
'scope' => 'private',
834+
'scope_specified' => true,
835+
'is_static' => false,
836+
'is_readonly' => false,
837+
'type' => 'int|string|true',
838+
'nullable_type' => false,
839+
],
840+
],
841+
[
842+
'/* testPHP82PseudoTypeFalseAndTrue */',
843+
[
844+
'scope' => 'public',
845+
'scope_specified' => false,
846+
'is_static' => false,
847+
'is_readonly' => true,
848+
'type' => 'true|FALSE',
849+
'nullable_type' => false,
850+
],
851+
],
852+
808853
];
809854

810855
}//end dataGetMemberProperties()

0 commit comments

Comments
 (0)