mirror of
https://github.com/php/php-src.git
synced 2024-09-22 02:17:32 +00:00
b10416a652
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.
66 lines
1.3 KiB
PHP
66 lines
1.3 KiB
PHP
--TEST--
|
|
Test strtr() function : usage variations - empty string & null for 'str' argument
|
|
--FILE--
|
|
<?php
|
|
/* Testing strtr() function by passing the
|
|
* empty string & null for 'str' argument and
|
|
* corresponding translation pair of chars for 'from', 'to' & 'replace_pairs' arguments
|
|
*/
|
|
|
|
echo "*** Testing strtr() : empty string & null for 'str' arg ***\n";
|
|
/* definitions of required input variables */
|
|
$count = 1;
|
|
|
|
$heredoc_str = <<<EOD
|
|
|
|
EOD;
|
|
|
|
//array of string inputs for $str
|
|
$str_arr = array(
|
|
"",
|
|
'',
|
|
FALSE,
|
|
false,
|
|
$heredoc_str
|
|
);
|
|
|
|
$from = "";
|
|
$to = "TEST";
|
|
$replace_pairs = array("" => "t", '' => "TEST");
|
|
|
|
|
|
/* loop through to test strtr() with each element of $str_arr */
|
|
for($index = 0; $index < count($str_arr); $index++) {
|
|
echo "-- Iteration $count --\n";
|
|
|
|
$str = $str_arr[$index]; //getting the array element in 'str' variable
|
|
|
|
//strtr() call in three args syntax form
|
|
var_dump( strtr($str, $from, $to) );
|
|
|
|
//strtr() call in two args syntax form
|
|
var_dump( strtr($str, $replace_pairs) );
|
|
|
|
$count++;
|
|
}
|
|
echo "*** Done ***";
|
|
?>
|
|
--EXPECT--
|
|
*** Testing strtr() : empty string & null for 'str' arg ***
|
|
-- Iteration 1 --
|
|
string(0) ""
|
|
string(0) ""
|
|
-- Iteration 2 --
|
|
string(0) ""
|
|
string(0) ""
|
|
-- Iteration 3 --
|
|
string(0) ""
|
|
string(0) ""
|
|
-- Iteration 4 --
|
|
string(0) ""
|
|
string(0) ""
|
|
-- Iteration 5 --
|
|
string(0) ""
|
|
string(0) ""
|
|
*** Done ***
|