Skip to content

Commit e038e40

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 7873cc4 commit e038e40

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
@@ -1849,6 +1849,7 @@ public function getMemberProperties($stackPtr)
18491849
T_SELF => T_SELF,
18501850
T_PARENT => T_PARENT,
18511851
T_FALSE => T_FALSE,
1852+
T_TRUE => T_TRUE,
18521853
T_NULL => T_NULL,
18531854
T_TYPE_INTERSECTION => T_TYPE_INTERSECTION,
18541855
T_TYPE_UNION => T_TYPE_UNION,

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
@@ -802,7 +802,7 @@ public function dataGetMemberProperties()
802802
],
803803
],
804804
[
805-
'/* testPHP81NulltableIntersectionType */',
805+
'/* testPHP81NullableIntersectionType */',
806806
[
807807
'scope' => 'public',
808808
'scope_specified' => true,
@@ -812,6 +812,51 @@ public function dataGetMemberProperties()
812812
'nullable_type' => true,
813813
],
814814
],
815+
[
816+
'/* testPHP82PseudoTypeTrue */',
817+
[
818+
'scope' => 'public',
819+
'scope_specified' => true,
820+
'is_static' => false,
821+
'is_readonly' => false,
822+
'type' => 'true',
823+
'nullable_type' => false,
824+
],
825+
],
826+
[
827+
'/* testPHP82NullablePseudoTypeTrue */',
828+
[
829+
'scope' => 'protected',
830+
'scope_specified' => true,
831+
'is_static' => true,
832+
'is_readonly' => false,
833+
'type' => '?true',
834+
'nullable_type' => true,
835+
],
836+
],
837+
[
838+
'/* testPHP82PseudoTypeTrueInUnion */',
839+
[
840+
'scope' => 'private',
841+
'scope_specified' => true,
842+
'is_static' => false,
843+
'is_readonly' => false,
844+
'type' => 'int|string|true',
845+
'nullable_type' => false,
846+
],
847+
],
848+
[
849+
'/* testPHP82PseudoTypeFalseAndTrue */',
850+
[
851+
'scope' => 'public',
852+
'scope_specified' => false,
853+
'is_static' => false,
854+
'is_readonly' => true,
855+
'type' => 'true|FALSE',
856+
'nullable_type' => false,
857+
],
858+
],
859+
815860
];
816861

817862
}//end dataGetMemberProperties()

0 commit comments

Comments
 (0)