1
0
mirror of https://github.com/php/php-src.git synced 2026-04-18 21:41:22 +02:00
Files
archived-php-src/ext/mbstring/tests/mb_str_functions_opt-parameter.phpt
Nikita Popov b10416a652 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.
2021-02-11 21:46:13 +01:00

48 lines
1.8 KiB
PHP

--TEST--
Optional long parameter might be null (deprecated)
--SKIPIF--
<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
--FILE--
<?php
echo mb_strpos('abb', 'b', null, 'UTF-8') . "\n";
echo mb_strrpos('abb', 'b', null, 'UTF-8') . "\n";
echo mb_stripos('abb', 'B', null, 'UTF-8') . "\n";
echo mb_strripos('abb', 'B', null, 'UTF-8') . "\n";
echo mb_strstr('foobarbaz', 'ba', null, 'UTF-8') . "\n";
echo mb_strrchr('foobarbaz', 'ba', null, 'UTF-8') . "\n";
echo mb_stristr('foobarbaz', 'BA', null, 'UTF-8') . "\n";
echo mb_strrichr('foobarbaz', 'BA', null, 'UTF-8') . "\n";
echo mb_substr('foobarbaz', 6, null, 'UTF-8') . "\n";
echo mb_strcut('foobarbaz', 6, null, 'UTF-8') . "\n";
echo mb_strimwidth('foobar', 0, 3, null, 'UTF-8') . "\n";
?>
--EXPECTF--
Deprecated: mb_strpos(): Passing null to parameter #3 ($offset) of type int is deprecated in %s on line %d
1
Deprecated: mb_strrpos(): Passing null to parameter #3 ($offset) of type int is deprecated in %s on line %d
2
Deprecated: mb_stripos(): Passing null to parameter #3 ($offset) of type int is deprecated in %s on line %d
1
Deprecated: mb_strripos(): Passing null to parameter #3 ($offset) of type int is deprecated in %s on line %d
2
Deprecated: mb_strstr(): Passing null to parameter #3 ($before_needle) of type bool is deprecated in %s on line %d
barbaz
Deprecated: mb_strrchr(): Passing null to parameter #3 ($before_needle) of type bool is deprecated in %s on line %d
baz
Deprecated: mb_stristr(): Passing null to parameter #3 ($before_needle) of type bool is deprecated in %s on line %d
barbaz
Deprecated: mb_strrichr(): Passing null to parameter #3 ($before_needle) of type bool is deprecated in %s on line %d
baz
baz
baz
Deprecated: mb_strimwidth(): Passing null to parameter #4 ($trim_marker) of type string is deprecated in %s on line %d
foo