Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cb0a96b

Browse filesBrowse files
committed
Allow false as standalone type
1 parent 1b0cdf8 commit cb0a96b
Copy full SHA for cb0a96b

7 files changed

+37
-17
lines changed
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Test typed properties allow false
3+
--FILE--
4+
<?php
5+
class Foo {
6+
public false $value;
7+
}
8+
9+
$foo = new Foo();
10+
?>
11+
===DONE===
12+
--EXPECT--
13+
===DONE===
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
--TEST--
2-
False cannot be used as a standalone type
2+
False can be used as a standalone type
33
--FILE--
44
<?php
55

66
function test(): false {}
77

88
?>
9-
--EXPECTF--
10-
Fatal error: false cannot be used as a standalone type in %s on line %d
9+
===DONE===
10+
--EXPECT--
11+
===DONE===
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
--TEST--
2-
False cannot be used as a standalone type even with implicit nullability
2+
False can be used as a standalone type even with implicit nullability
33
--FILE--
44
<?php
55

66
function test(false $v = null) {}
77

88
?>
9-
--EXPECTF--
10-
Fatal error: false cannot be used as a standalone type in %s on line %d
9+
===DONE===
10+
--EXPECT--
11+
===DONE===
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
--TEST--
2-
Nullable false cannot be used as a standalone type
2+
Nullable false can be used as a standalone type
33
--FILE--
44
<?php
55

66
function test(): ?false {}
77

88
?>
9-
--EXPECTF--
10-
Fatal error: false cannot be marked as nullable since false is not a standalone type in %s on line %d
9+
===DONE===
10+
--EXPECT--
11+
===DONE===

‎Zend/zend_compile.c

Copy file name to clipboardExpand all lines: Zend/zend_compile.c
-8Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6345,14 +6345,6 @@ static zend_type zend_compile_typename(
63456345
zend_error_noreturn(E_COMPILE_ERROR, "null cannot be marked as nullable");
63466346
}
63476347

6348-
if ((type_mask & MAY_BE_FALSE) && !ZEND_TYPE_IS_COMPLEX(type) && !(type_mask & ~MAY_BE_FALSE)) {
6349-
if (is_marked_nullable) {
6350-
zend_error_noreturn(E_COMPILE_ERROR, "false cannot be marked as nullable since false is not a standalone type");
6351-
} else {
6352-
zend_error_noreturn(E_COMPILE_ERROR, "false cannot be used as a standalone type");
6353-
}
6354-
}
6355-
63566348
if (is_marked_nullable || force_allow_null) {
63576349
ZEND_TYPE_FULL_MASK(type) |= MAY_BE_NULL;
63586350
type_mask = ZEND_TYPE_PURE_MASK(type);

‎ext/reflection/tests/ReflectionType_possible_types.phpt

Copy file name to clipboardExpand all lines: ext/reflection/tests/ReflectionType_possible_types.phpt
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ $functions = [
1313
function(): callable {},
1414
function(): iterable {},
1515
function(): null {},
16+
function(): false {},
1617
function(): StdClass {}
1718
];
1819

@@ -32,4 +33,5 @@ string(5) "array"
3233
string(8) "callable"
3334
string(8) "iterable"
3435
string(4) "null"
36+
string(5) "false"
3537
string(8) "StdClass"

‎ext/reflection/tests/union_types.phpt

Copy file name to clipboardExpand all lines: ext/reflection/tests/union_types.phpt
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ function dumpType(ReflectionUnionType $rt) {
1616
function test1(): X|Y|int|float|false|null { }
1717
function test2(): X|iterable|bool { }
1818
function test3(): null|false { }
19+
function test4(): ?false { }
1920

2021
class Test {
2122
public X|Y|int $prop;
@@ -24,6 +25,7 @@ class Test {
2425
dumpType((new ReflectionFunction('test1'))->getReturnType());
2526
dumpType((new ReflectionFunction('test2'))->getReturnType());
2627
dumpType((new ReflectionFunction('test3'))->getReturnType());
28+
dumpType((new ReflectionFunction('test4'))->getReturnType());
2729

2830
$rc = new ReflectionClass(Test::class);
2931
$rp = $rc->getProperty('prop');
@@ -78,6 +80,14 @@ Allows null: false
7880
String: bool
7981
Allows Null: false
8082
Type false|null:
83+
Allows null: true
84+
Name: false
85+
String: false
86+
Allows Null: false
87+
Name: null
88+
String: null
89+
Allows Null: true
90+
Type false|null:
8191
Allows null: true
8292
Name: false
8393
String: false

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.