summaryrefslogtreecommitdiff
path: root/Zend/tests
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-11-30 16:45:48 +0100
committerNikita Popov <nikita.ppv@gmail.com>2021-02-11 21:46:13 +0100
commitb10416a652d26577a22fe0b183b2258b20c8bb86 (patch)
tree3b79102286b2307575f487bf97d572ffc292631d /Zend/tests
parentf06895488a5fabd27ac4c2e66a9d311f14d8594e (diff)
downloadphp-git-b10416a652d26577a22fe0b183b2258b20c8bb86.tar.gz
Deprecate passing null to non-nullable arg of internal function
This deprecates passing null to non-nullable scale arguments of internal functions, with the eventual goal of making the behavior consistent with userland functions, where null is never accepted for non-nullable arguments. This change is expected to cause quite a lot of fallout. In most cases, calling code should be adjusted to avoid passing null. In some cases, PHP should be adjusted to make some function arguments nullable. I have already fixed a number of functions before landing this, but feel free to file a bug if you encounter a function that doesn't accept null, but probably should. (The rule of thumb for this to be applicable is that the function must have special behavior for 0 or "", which is distinct from the natural behavior of the parameter.) RFC: https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg Closes GH-6475.
Diffstat (limited to 'Zend/tests')
-rw-r--r--Zend/tests/bug43201.phpt12
-rw-r--r--Zend/tests/bug64677.phpt2
-rw-r--r--Zend/tests/class_exists_002.phpt2
-rw-r--r--Zend/tests/exception_001.phpt2
-rw-r--r--Zend/tests/interface_exists_001.phpt2
-rw-r--r--Zend/tests/null_to_non_nullable_special_func.phpt12
-rw-r--r--Zend/tests/nullsafe_operator/013.phpt9
-rw-r--r--Zend/tests/str_or_obj_of_class_zpp.phpt4
-rw-r--r--Zend/tests/str_or_obj_zpp.phpt4
-rw-r--r--Zend/tests/trait_exists_001.phpt2
10 files changed, 41 insertions, 10 deletions
diff --git a/Zend/tests/bug43201.phpt b/Zend/tests/bug43201.phpt
index 49816ea1c1..c93b118e16 100644
--- a/Zend/tests/bug43201.phpt
+++ b/Zend/tests/bug43201.phpt
@@ -30,25 +30,37 @@ Warning: Undefined variable $ref in %s on line %d
Warning: Undefined variable $undef in %s on line %d
+Deprecated: chop(): Passing null to parameter #1 ($string) of type string is deprecated in %s on line %d
+
Notice: Indirect modification of overloaded property Foo::$arr has no effect in %sbug43201.php on line 17
Warning: Undefined variable $undef in %s on line %d
+Deprecated: chop(): Passing null to parameter #1 ($string) of type string is deprecated in %s on line %d
+
Notice: Indirect modification of overloaded property Foo::$arr has no effect in %sbug43201.php on line 17
Warning: Undefined variable $undef in %s on line %d
+Deprecated: chop(): Passing null to parameter #1 ($string) of type string is deprecated in %s on line %d
+
Notice: Indirect modification of overloaded property Foo::$arr has no effect in %sbug43201.php on line 17
Warning: Undefined variable $undef in %s on line %d
+Deprecated: chop(): Passing null to parameter #1 ($string) of type string is deprecated in %s on line %d
+
Notice: Indirect modification of overloaded property Foo::$arr has no effect in %sbug43201.php on line 17
Warning: Undefined variable $undef in %s on line %d
+Deprecated: chop(): Passing null to parameter #1 ($string) of type string is deprecated in %s on line %d
+
Notice: Indirect modification of overloaded property Foo::$arr has no effect in %sbug43201.php on line 17
Warning: Undefined variable $undef in %s on line %d
+Deprecated: chop(): Passing null to parameter #1 ($string) of type string is deprecated in %s on line %d
+
Notice: Indirect modification of overloaded property Foo::$arr has no effect in %sbug43201.php on line 17
ok
diff --git a/Zend/tests/bug64677.phpt b/Zend/tests/bug64677.phpt
index 2dcd00ce0a..c3b168bd83 100644
--- a/Zend/tests/bug64677.phpt
+++ b/Zend/tests/bug64677.phpt
@@ -7,7 +7,7 @@ class cat {
}
}
$cat = new cat();
-$cat->show_output('Files: ', trim(`cd .`)); // this gives invalid args to shell_exec
+$cat->show_output('Files: ', trim((string) `cd .`)); // this gives invalid args to shell_exec
$cat->show_output('Files: ', `cd .`); // this causes a segmentation fault
$cat->show_output(`cd .`); // this causes a segmentation fault
diff --git a/Zend/tests/class_exists_002.phpt b/Zend/tests/class_exists_002.phpt
index 5e5df1d371..e020c1d623 100644
--- a/Zend/tests/class_exists_002.phpt
+++ b/Zend/tests/class_exists_002.phpt
@@ -8,7 +8,6 @@ class foo {
}
var_dump(class_exists(''));
-var_dump(class_exists(NULL));
var_dump(class_exists('FOO'));
var_dump(class_exists('bar'));
var_dump(class_exists(1));
@@ -16,7 +15,6 @@ var_dump(class_exists(1));
?>
--EXPECT--
bool(false)
-bool(false)
bool(true)
bool(false)
bool(false)
diff --git a/Zend/tests/exception_001.phpt b/Zend/tests/exception_001.phpt
index 232ef012ed..aba29d4aa3 100644
--- a/Zend/tests/exception_001.phpt
+++ b/Zend/tests/exception_001.phpt
@@ -7,7 +7,7 @@ try {
try {
try {
try {
- throw new Exception(NULL);
+ throw new Exception();
} catch (Exception $e) {
var_dump($e->getMessage());
throw $e;
diff --git a/Zend/tests/interface_exists_001.phpt b/Zend/tests/interface_exists_001.phpt
index 84e9c6df1e..4bc01221a8 100644
--- a/Zend/tests/interface_exists_001.phpt
+++ b/Zend/tests/interface_exists_001.phpt
@@ -8,10 +8,8 @@ interface foo {
var_dump(interface_exists('foo'));
var_dump(interface_exists(1));
-var_dump(interface_exists(NULL));
?>
--EXPECT--
bool(true)
bool(false)
-bool(false)
diff --git a/Zend/tests/null_to_non_nullable_special_func.phpt b/Zend/tests/null_to_non_nullable_special_func.phpt
new file mode 100644
index 0000000000..9dc1c96f72
--- /dev/null
+++ b/Zend/tests/null_to_non_nullable_special_func.phpt
@@ -0,0 +1,12 @@
+--TEST--
+Test null arg behavior for special functions
+--FILE--
+<?php
+
+$null = null;
+var_dump(strlen($null));
+
+?>
+--EXPECTF--
+Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in %s on line %d
+int(0)
diff --git a/Zend/tests/nullsafe_operator/013.phpt b/Zend/tests/nullsafe_operator/013.phpt
index fd1fbc9006..595f292f6f 100644
--- a/Zend/tests/nullsafe_operator/013.phpt
+++ b/Zend/tests/nullsafe_operator/013.phpt
@@ -38,14 +38,21 @@ dump_error(fn() => array_key_exists('foo', $foo?->foo()));
?>
--EXPECTF--
+Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in %s on line %d
int(0)
bool(true)
bool(false)
bool(false)
bool(false)
bool(false)
+
+Deprecated: defined(): Passing null to parameter #1 ($constant_name) of type string is deprecated in %s on line %d
bool(false)
+
+Deprecated: chr(): Passing null to parameter #1 ($codepoint) of type int is deprecated in %s on line %d
string(1) "%s"
+
+Deprecated: ord(): Passing null to parameter #1 ($character) of type string is deprecated in %s on line %d
int(0)
string(98) "call_user_func_array(): Argument #1 ($function) must be a valid callback, no array or string given"
string(77) "call_user_func_array(): Argument #2 ($args) must be of type array, null given"
@@ -55,6 +62,8 @@ string(4) "NULL"
string(52) "func_num_args() expects exactly 0 arguments, 1 given"
string(52) "func_get_args() expects exactly 0 arguments, 1 given"
string(69) "array_slice(): Argument #1 ($array) must be of type array, null given"
+
+Deprecated: array_slice(): Passing null to parameter #2 ($offset) of type int is deprecated in %s on line %d
array(1) {
[0]=>
string(3) "foo"
diff --git a/Zend/tests/str_or_obj_of_class_zpp.phpt b/Zend/tests/str_or_obj_of_class_zpp.phpt
index 6f6a155895..04a321a692 100644
--- a/Zend/tests/str_or_obj_of_class_zpp.phpt
+++ b/Zend/tests/str_or_obj_of_class_zpp.phpt
@@ -51,9 +51,11 @@ try {
}
?>
---EXPECT--
+--EXPECTF--
string(6) "string"
string(1) "1"
+
+Deprecated: zend_string_or_stdclass(): Passing null to parameter #1 ($param) of type string is deprecated in %s on line %d
string(0) ""
object(stdClass)#1 (0) {
}
diff --git a/Zend/tests/str_or_obj_zpp.phpt b/Zend/tests/str_or_obj_zpp.phpt
index 6328c61b2d..00eec7a688 100644
--- a/Zend/tests/str_or_obj_zpp.phpt
+++ b/Zend/tests/str_or_obj_zpp.phpt
@@ -34,9 +34,11 @@ try {
}
?>
---EXPECT--
+--EXPECTF--
string(6) "string"
string(1) "1"
+
+Deprecated: zend_string_or_object(): Passing null to parameter #1 ($param) of type object|string is deprecated in %s on line %d
string(0) ""
object(stdClass)#1 (0) {
}
diff --git a/Zend/tests/trait_exists_001.phpt b/Zend/tests/trait_exists_001.phpt
index 8a7c55d586..8699b07cef 100644
--- a/Zend/tests/trait_exists_001.phpt
+++ b/Zend/tests/trait_exists_001.phpt
@@ -8,10 +8,8 @@ trait foo {
var_dump(trait_exists('foo'));
var_dump(trait_exists(1));
-var_dump(trait_exists(NULL));
?>
--EXPECT--
bool(true)
bool(false)
-bool(false)