Skip to content

Commit 00e1b5f

Browse files
committed
Deprecate implicit nullable parameter types
1 parent d629920 commit 00e1b5f

Some content is hidden

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

47 files changed

+175
-132
lines changed

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
}

Zend/tests/ns_074.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Testing type-hinted lambda parameter inside namespace
55

66
namespace foo;
77

8-
$x = function (\stdclass $x = NULL) {
8+
$x = function (?\stdclass $x = NULL) {
99
var_dump($x);
1010
};
1111

Zend/tests/required_param_after_optional.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ Deprecated: Optional parameter $testA declared before required parameter $testC
1313

1414
Deprecated: Optional parameter $testB declared before required parameter $testC is implicitly treated as a required parameter in %s on line %d
1515

16+
Deprecated: Implicitly marking parameter $test2A as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
17+
1618
Deprecated: Optional parameter $test2B declared before required parameter $test2C is implicitly treated as a required parameter in %s on line %d
1719

20+
Deprecated: Implicitly marking parameter $test3A as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
21+
1822
Deprecated: Optional parameter $test3B declared before required parameter $test3C is implicitly treated as a required parameter in %s on line %d

Zend/tests/traits/bug60717.phpt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,10 @@ namespace HTML
6969
echo 'Done';
7070
}
7171
?>
72-
--EXPECT--
72+
--EXPECTF--
73+
Deprecated: Implicitly marking parameter $attributes as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
74+
75+
Deprecated: Implicitly marking parameter $attributes as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
76+
77+
Deprecated: Implicitly marking parameter $attributes as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
7378
Done

Zend/tests/type_declarations/callable_003.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ function bar(callable $a = null) {
1313
foo("strpos", 123, "strpos");
1414
bar("substr");
1515
?>
16-
--EXPECT--
16+
--EXPECTF--
17+
Deprecated: Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
1718
string(6) "strpos"
1819
int(123)
1920
string(6) "strpos"

Zend/tests/type_declarations/intersection_types/implicit_nullable_intersection_type.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ function foo(X&Y $foo = null) {
1010
foo(null);
1111

1212
?>
13-
--EXPECT--
13+
--EXPECTF--
14+
Deprecated: Implicitly marking parameter $foo as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
1415
NULL

Zend/tests/type_declarations/intersection_types/implicit_nullable_intersection_type_error.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ try {
1515

1616
?>
1717
--EXPECTF--
18+
Deprecated: Implicitly marking parameter $foo as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
1819
foo(): Argument #1 ($foo) must be of type (X&Y)|null, int given, called in %s on line %d

Zend/tests/type_declarations/iterable/iterable_002.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ function baz(iterable $iterable = 1) {
1717

1818
?>
1919
--EXPECTF--
20+
Deprecated: Implicitly marking parameter $iterable as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
21+
2022
Fatal error: Cannot use int as default value for parameter $iterable of type Traversable|array in %s on line %d

Zend/tests/type_declarations/literal_types/false_standalone_implicit_nullability.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ function test(false $v = null) { return $v; }
88
var_dump(test(false));
99
var_dump(test(null));
1010
?>
11-
--EXPECT--
11+
--EXPECTF--
12+
Deprecated: Implicitly marking parameter $v as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
1213
bool(false)
1314
NULL

Zend/tests/type_declarations/literal_types/true_standalone_implicit_nullability.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ function test(true $v = null) { return $v; }
88
var_dump(test(true));
99
var_dump(test(null));
1010
?>
11-
--EXPECT--
11+
--EXPECTF--
12+
Deprecated: Implicitly marking parameter $v as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
1213
bool(true)
1314
NULL

Zend/tests/type_declarations/nullable_null.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ function test(Foo $a = null) {
77
}
88
test(null);
99
?>
10-
--EXPECT--
10+
--EXPECTF--
11+
Deprecated: Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
1112
ok

Zend/tests/type_declarations/scalar_none.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ $functions = [
88
'float' => function (float $f) { return $f; },
99
'string' => function (string $s) { return $s; },
1010
'bool' => function (bool $b) { return $b; },
11-
'int nullable' => function (int $i = NULL) { return $i; },
12-
'float nullable' => function (float $f = NULL) { return $f; },
13-
'string nullable' => function (string $s = NULL) { return $s; },
14-
'bool nullable' => function (bool $b = NULL) { return $b; }
11+
'int nullable' => function (?int $i = NULL) { return $i; },
12+
'float nullable' => function (?float $f = NULL) { return $f; },
13+
'string nullable' => function (?string $s = NULL) { return $s; },
14+
'bool nullable' => function (?bool $b = NULL) { return $b; }
1515
];
1616

1717
foreach ($functions as $type => $function) {

Zend/tests/type_declarations/scalar_null.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ $functions = [
88
'float' => function (float $f) { return $f; },
99
'string' => function (string $s) { return $s; },
1010
'bool' => function (bool $b) { return $b; },
11-
'int nullable' => function (int $i = NULL) { return $i; },
12-
'float nullable' => function (float $f = NULL) { return $f; },
13-
'string nullable' => function (string $s = NULL) { return $s; },
14-
'bool nullable' => function (bool $b = NULL) { return $b; }
11+
'int nullable' => function (?int $i = NULL) { return $i; },
12+
'float nullable' => function (?float $f = NULL) { return $f; },
13+
'string nullable' => function (?string $s = NULL) { return $s; },
14+
'bool nullable' => function (?bool $b = NULL) { return $b; }
1515
];
1616

1717
foreach ($functions as $type => $function) {

Zend/tests/type_declarations/variance/internal_parent/unresolvable_inheritance_check_param.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Test unresolvable inheritance check due to unavailable parameter type when the p
44
<?php
55

66
class Test extends DateTime {
7-
public static function createFromFormat($format, $datetime, Wrong $timezone = null): DateTime|false {}
7+
public static function createFromFormat($format, $datetime, ?Wrong $timezone = null): DateTime|false {}
88
}
99

1010
?>

Zend/tests/variadic/adding_additional_optional_parameter.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ class MySQL implements DB {
1313

1414
?>
1515
===DONE===
16-
--EXPECT--
16+
--EXPECTF--
17+
Deprecated: Implicitly marking parameter $extraParam as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
1718
===DONE===

Zend/tests/variadic/adding_additional_optional_parameter_error.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ class MySQL implements DB {
1313

1414
?>
1515
--EXPECTF--
16+
Deprecated: Implicitly marking parameter $extraParam as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
17+
1618
Fatal error: Declaration of MySQL::query($query, ?int $extraParam = null, string ...$params) must be compatible with DB::query($query, string ...$params) in %s on line %d

Zend/zend_compile.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6560,7 +6560,7 @@ static void zend_is_type_list_redundant_by_single_type(zend_type_list *type_list
65606560
}
65616561
}
65626562

6563-
static zend_type zend_compile_typename(zend_ast *ast, bool force_allow_null);
6563+
static zend_type zend_compile_typename(zend_ast *ast);
65646564

65656565
static zend_type zend_compile_typename_ex(
65666566
zend_ast *ast, bool force_allow_null, bool *forced_allow_null) /* {{{ */
@@ -6601,7 +6601,7 @@ static zend_type zend_compile_typename_ex(
66016601
/* Mark type as list type */
66026602
ZEND_TYPE_SET_LIST(type, type_list);
66036603

6604-
single_type = zend_compile_typename(type_ast, false);
6604+
single_type = zend_compile_typename(type_ast);
66056605
ZEND_ASSERT(ZEND_TYPE_IS_INTERSECTION(single_type));
66066606

66076607
type_list->types[type_list->num_types++] = single_type;
@@ -6788,10 +6788,10 @@ static zend_type zend_compile_typename_ex(
67886788
}
67896789
/* }}} */
67906790

6791-
static zend_type zend_compile_typename(zend_ast *ast, bool force_allow_null)
6791+
static zend_type zend_compile_typename(zend_ast *ast)
67926792
{
67936793
bool forced_allow_null;
6794-
return zend_compile_typename_ex(ast, force_allow_null, &forced_allow_null);
6794+
return zend_compile_typename_ex(ast, false, &forced_allow_null);
67956795
}
67966796

67976797
/* May convert value from int to float. */
@@ -6937,8 +6937,7 @@ static void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32
69376937
arg_infos = safe_emalloc(sizeof(zend_arg_info), list->children + 1, 0);
69386938
arg_infos->name = NULL;
69396939
if (return_type_ast) {
6940-
arg_infos->type = zend_compile_typename(
6941-
return_type_ast, /* force_allow_null */ 0);
6940+
arg_infos->type = zend_compile_typename(return_type_ast);
69426941
ZEND_TYPE_FULL_MASK(arg_infos->type) |= _ZEND_ARG_INFO_FLAGS(
69436942
(op_array->fn_flags & ZEND_ACC_RETURN_REFERENCE) != 0, /* is_variadic */ 0, /* is_tentative */ 0);
69446943
} else {
@@ -7047,6 +7046,11 @@ static void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32
70477046

70487047
op_array->fn_flags |= ZEND_ACC_HAS_TYPE_HINTS;
70497048
arg_info->type = zend_compile_typename_ex(type_ast, force_nullable, &forced_allow_nullable);
7049+
if (forced_allow_nullable) {
7050+
zend_error(E_DEPRECATED,
7051+
"Implicitly marking parameter $%s as nullable is deprecated, the explicit nullable type "
7052+
"must be used instead", ZSTR_VAL(name));
7053+
}
70507054

70517055
if (ZEND_TYPE_FULL_MASK(arg_info->type) & MAY_BE_VOID) {
70527056
zend_error_noreturn(E_COMPILE_ERROR, "void cannot be used as a parameter type");
@@ -7141,7 +7145,7 @@ static void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32
71417145
/* Recompile the type, as it has different memory management requirements. */
71427146
zend_type type = ZEND_TYPE_INIT_NONE(0);
71437147
if (type_ast) {
7144-
type = zend_compile_typename(type_ast, /* force_allow_null */ 0);
7148+
type = zend_compile_typename(type_ast);
71457149
}
71467150

71477151
/* Don't give the property an explicit default value. For typed properties this means
@@ -7715,7 +7719,7 @@ static void zend_compile_prop_decl(zend_ast *ast, zend_ast *type_ast, uint32_t f
77157719
zend_type type = ZEND_TYPE_INIT_NONE(0);
77167720

77177721
if (type_ast) {
7718-
type = zend_compile_typename(type_ast, /* force_allow_null */ 0);
7722+
type = zend_compile_typename(type_ast);
77197723

77207724
if (ZEND_TYPE_FULL_MASK(type) & (MAY_BE_VOID|MAY_BE_NEVER|MAY_BE_CALLABLE)) {
77217725
zend_string *str = zend_type_to_string(type);
@@ -7830,7 +7834,7 @@ static void zend_compile_class_const_decl(zend_ast *ast, uint32_t flags, zend_as
78307834
zend_type type = ZEND_TYPE_INIT_NONE(0);
78317835

78327836
if (type_ast) {
7833-
type = zend_compile_typename(type_ast, /* force_allow_null */ 0);
7837+
type = zend_compile_typename(type_ast);
78347838

78357839
uint32_t type_mask = ZEND_TYPE_PURE_MASK(type);
78367840

@@ -8023,7 +8027,7 @@ static zend_string *zend_generate_anon_class_name(zend_ast_decl *decl)
80238027
static void zend_compile_enum_backing_type(zend_class_entry *ce, zend_ast *enum_backing_type_ast)
80248028
{
80258029
ZEND_ASSERT(ce->ce_flags & ZEND_ACC_ENUM);
8026-
zend_type type = zend_compile_typename(enum_backing_type_ast, 0);
8030+
zend_type type = zend_compile_typename(enum_backing_type_ast);
80278031
uint32_t type_mask = ZEND_TYPE_PURE_MASK(type);
80288032
if (ZEND_TYPE_IS_COMPLEX(type) || (type_mask != MAY_BE_LONG && type_mask != MAY_BE_STRING)) {
80298033
zend_string *type_string = zend_type_to_string(type);

ext/date/tests/DateTime_extends_basic2.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ echo "*** Testing new DateTime() : with user space __construct magic method ***\
1010

1111
class DateTimeExt extends DateTime
1212
{
13-
public function __construct ($date = null, DateTimeZone $dtz = null)
13+
public function __construct ($date = null, ?DateTimeZone $dtz = null)
1414
{
1515
if($dtz === null)
1616
{

ext/date/tests/bug55407.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ error_reporting=-1
66
<?php namespace melt\core;
77

88
class DateTime extends \DateTime {
9-
public static function createFromFormat($format, $time, \DateTimeZone $timezone = null): DateTime|false {
9+
public static function createFromFormat($format, $time, ?\DateTimeZone $timezone = null): DateTime|false {
1010
return new DateTime(parent::createFromFormat($format, $time, $timezone));
1111
}
1212
}

ext/opcache/tests/bug73746.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class CountryMapping
1111
const CZ = 'CZ';
1212
const EN = 'EN';
1313

14-
public function get(string $countryIsoCode = null) : string // Works correctly if return type is removed
14+
public function get(?string $countryIsoCode = null) : string // Works correctly if return type is removed
1515
{
1616
switch (strtoupper($countryIsoCode)) {
1717
case 'CZ':

ext/opcache/tests/bug74442.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ opcache
77
--FILE--
88
<?php
99
class Schema_Base {
10-
public function addField($typeclass, array $params = null) {
10+
public function addField($typeclass, ?array $params = null) {
1111
$field = new $typeclass($params);
1212
return $field;
1313
}
1414
}
1515

1616
class Field_Base {
17-
public function __construct(array $params = null) {
17+
public function __construct(?array $params = null) {
1818
if (! is_array($params)) {
1919
$params = (array) $params;
2020
}

ext/opcache/tests/invalid_array_key_type.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ opcache
55
--FILE--
66
<?php
77

8-
function test(\SplObjectStorage $definitions = null) {
8+
function test(?\SplObjectStorage $definitions = null) {
99
$argument = new stdClass;
1010
$definitions[$argument] = 1;
1111
$definitions[$argument] += 1;

ext/opcache/tests/jit/cast_001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ opcache.jit=1205
1111
opcache
1212
--FILE--
1313
<?php
14-
function foo (int $x = null) {
14+
function foo (?int $x = null) {
1515
$a = (array)$x;
1616
$a[] = 42;
1717
var_dump($a);

ext/opcache/tests/jit/send_var_ex_002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ for ($i = 0; $i < 3; $i++ ) {
1313
var_dump($x);
1414
}
1515

16-
function test(&$a = null, SomeType &$b = null) {
16+
function test(&$a = null, ?SomeType &$b = null) {
1717
$a++;
1818
}
1919
?>

ext/opcache/tests/opt/assign_op_002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ opcache.enable_cli=1
66
opcache.optimization_level=-1
77
--FILE--
88
<?php
9-
function foo(int $a = null) {
9+
function foo(?int $a = null) {
1010
$a -= 1;
1111
return $a;
1212
}

ext/pdo_pgsql/tests/bug72294.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ abstract class PHPUnit_Framework_TestCase
2727
private $name = null;
2828
private $result;
2929

30-
public function run(PHPUnit_Framework_TestResult $result = null)
30+
public function run(?PHPUnit_Framework_TestResult $result = null)
3131
{
3232
$result->run($this);
3333
}

0 commit comments

Comments
 (0)