Skip to content

Commit 330cc5c

Browse files
kocsismateGirgias
andauthored
Deprecate implicit nullable parameter types (#12959)
RFC: https://wiki.php.net/rfc/deprecate-implicitly-nullable-types Co-authored-by: Gina Peter Banyard <[email protected]>
1 parent b341036 commit 330cc5c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+170
-126
lines changed

UPGRADING

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ PHP 8.4 UPGRADE NOTES
268268
4. Deprecated Functionality
269269
========================================
270270

271+
- Core:
272+
. Implicitly nullable parameter types are now deprecated.
273+
RFC: https://wiki.php.net/rfc/deprecate-implicitly-nullable-types
274+
271275
- Curl:
272276
. The CURLOPT_BINARYTRANSFER constant is deprecated.
273277

Zend/tests/bug63635.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Node {
66
public $parent = NULL;
77
public $children = array();
88

9-
function __construct(Node $parent=NULL) {
9+
function __construct(?Node $parent=NULL) {
1010
if ($parent) {
1111
$parent->children[] = $this;
1212
}

Zend/tests/bug71428.1.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ bug #71428.1: inheritance with null default values
33
--FILE--
44
<?php
55
class A {
6-
public function m(array $a = null) {}
6+
public function m(?array $a = null) {}
77
}
88
class B extends A {
99
public function m(array $a = []) {}

Zend/tests/bug71428.3.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ class B { public function m(A $a = NULL, $n) { echo "B.m";} };
77
class C extends B { public function m(A $a , $n) { echo "C.m";} };
88
?>
99
--EXPECTF--
10+
Deprecated: Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
11+
1012
Fatal error: Declaration of C::m(A $a, $n) must be compatible with B::m(?A $a, $n) in %sbug71428.3.php on line 4

Zend/tests/bug72119.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Bug #72119 (Interface declaration compatibility regression with default values)
33
--FILE--
44
<?php
55
interface Foo {
6-
public function bar(array $baz = null);
6+
public function bar(?array $baz = null);
77
}
88

99
class Hello implements Foo {

Zend/tests/gh11488.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ function c(
1818
--EXPECTF--
1919
Deprecated: Optional parameter $a declared before required parameter $b is implicitly treated as a required parameter in %s on line %d
2020

21+
Deprecated: Implicitly marking parameter $c as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
22+
2123
Deprecated: Optional parameter $e declared before required parameter $f is implicitly treated as a required parameter in %s on line %d

Zend/tests/ns_070.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Testing parameter type-hinted with default value inside namespace
66
namespace foo;
77

88
class bar {
9-
public function __construct(\stdclass $x = NULL) {
9+
public function __construct(?\stdclass $x = NULL) {
1010
var_dump($x);
1111
}
1212
}

Zend/tests/ns_071.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Testing parameter type-hinted (array) with default value inside namespace
66
namespace foo;
77

88
class bar {
9-
public function __construct(array $x = NULL) {
9+
public function __construct(?array $x = NULL) {
1010
var_dump($x);
1111
}
1212
}

Zend/tests/ns_072.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ interface foo {
1010
}
1111

1212
class bar {
13-
public function __construct(foo $x = NULL) {
13+
public function __construct(?foo $x = NULL) {
1414
var_dump($x);
1515
}
1616
}

Zend/tests/ns_073.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ $x(new \stdclass);
1414

1515
?>
1616
--EXPECTF--
17+
Deprecated: Implicitly marking parameter $x as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
1718
NULL
1819
object(stdClass)#%d (0) {
1920
}

0 commit comments

Comments
 (0)