Skip to content

Commit 0af050c

Browse files
committed
Allow 'null' as a standalone type
1 parent 95ad1d1 commit 0af050c

14 files changed

+125
-24
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Null can be used as a standalone type
3+
--FILE--
4+
<?php
5+
6+
function test(null $v): null {
7+
return $v;
8+
}
9+
10+
var_dump(test(null));
11+
12+
?>
13+
===DONE===
14+
--EXPECT--
15+
NULL
16+
===DONE===
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Test typed properties allow null
3+
--FILE--
4+
<?php
5+
class Foo {
6+
public null $value;
7+
}
8+
9+
$foo = new Foo();
10+
?>
11+
===DONE===
12+
--EXPECT--
13+
===DONE===
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Typed null|false return without value generates compile-time error
3+
--FILE--
4+
<?php
5+
6+
function test() : null|false {
7+
return;
8+
}
9+
10+
test();
11+
12+
?>
13+
--EXPECTF--
14+
Fatal error: A function with return type must return a value (did you mean "return null;" instead of "return;"?) in %s on line %d
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Typed null return without value generates compile-time error
3+
--FILE--
4+
<?php
5+
6+
function test() : null {
7+
return;
8+
}
9+
10+
test();
11+
12+
?>
13+
--EXPECTF--
14+
Fatal error: A function with return type must return a value (did you mean "return null;" instead of "return;"?) in %s on line %d
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Null and false can be used in a union type
3+
--FILE--
4+
<?php
5+
6+
function test1(): null|false {}
7+
function test2(): false|null {}
8+
9+
?>
10+
===DONE===
11+
--EXPECT--
12+
===DONE===

Zend/tests/type_declarations/union_types/redundant_types/nullable_null.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ function test(): ?null {
88

99
?>
1010
--EXPECTF--
11-
Fatal error: Null cannot be used as a standalone type in %s on line %d
11+
Fatal error: null cannot be marked as nullable in %s on line %d

Zend/tests/type_declarations/union_types/standalone_false.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ function test(): false {}
77

88
?>
99
--EXPECTF--
10-
Fatal error: False cannot be used as a standalone type in %s on line %d
10+
Fatal error: false cannot be used as a standalone type in %s on line %d
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
False cannot be used as a standalone type even with implicit nullability
3+
--FILE--
4+
<?php
5+
6+
function test(false $v = null) {}
7+
8+
?>
9+
--EXPECTF--
10+
Fatal error: false cannot be used as a standalone type in %s on line %d
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
--TEST--
2-
Null cannot be used as a standalone type
2+
Null can be used as a standalone type
33
--FILE--
44
<?php
55

66
function test(): null {}
77

88
?>
9-
--EXPECTF--
10-
Fatal error: Null cannot be used as a standalone type in %s on line %d
9+
===DONE===
10+
--EXPECT--
11+
===DONE===

Zend/tests/type_declarations/union_types/standalone_nullable_false.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ function test(): ?false {}
77

88
?>
99
--EXPECTF--
10-
Fatal error: False cannot be used as a standalone type in %s on line %d
10+
Fatal error: false cannot be marked as nullable since false is not a standalone type in %s on line %d

0 commit comments

Comments
 (0)