mirror of
https://github.com/php/php-src.git
synced 2026-04-18 13:31:27 +02:00
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.
149 lines
2.8 KiB
PHP
149 lines
2.8 KiB
PHP
--TEST--
|
|
Test bindec() function : usage variations - different data types as $binary_string arg
|
|
--SKIPIF--
|
|
<?php
|
|
if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
|
|
?>
|
|
--FILE--
|
|
<?php
|
|
echo "*** Testing bindec() : usage variations ***\n";
|
|
|
|
// heredoc string
|
|
$heredoc = <<<EOT
|
|
abc
|
|
xyz
|
|
EOT;
|
|
|
|
// get a resource variable
|
|
$fp = fopen(__FILE__, "r");
|
|
|
|
$inputs = array(
|
|
// int data
|
|
/*1*/ 0,
|
|
1,
|
|
12345,
|
|
-2345,
|
|
|
|
// float data
|
|
/*5*/ 10.5,
|
|
-10.5,
|
|
12.3456789000e10,
|
|
12.3456789000E-10,
|
|
.5,
|
|
|
|
// boolean data
|
|
/*12*/ true,
|
|
false,
|
|
TRUE,
|
|
FALSE,
|
|
|
|
// empty data
|
|
/*16*/ "",
|
|
'',
|
|
array(),
|
|
|
|
// string data
|
|
/*19*/ "abcxyz",
|
|
'abcxyz',
|
|
$heredoc,
|
|
|
|
// resource variable
|
|
/*24*/ $fp
|
|
);
|
|
|
|
// loop through each element of $inputs to check the behaviour of bindec()
|
|
$iterator = 1;
|
|
foreach($inputs as $input) {
|
|
echo "\n-- Iteration $iterator --\n";
|
|
try {
|
|
var_dump(bindec($input));
|
|
} catch (TypeError $e) {
|
|
echo $e->getMessage(), "\n";
|
|
}
|
|
$iterator++;
|
|
};
|
|
fclose($fp);
|
|
?>
|
|
--EXPECTF--
|
|
*** Testing bindec() : usage variations ***
|
|
|
|
-- Iteration 1 --
|
|
int(0)
|
|
|
|
-- Iteration 2 --
|
|
int(1)
|
|
|
|
-- Iteration 3 --
|
|
|
|
Deprecated: Invalid characters passed for attempted conversion, these have been ignored in %s on line %d
|
|
int(1)
|
|
|
|
-- Iteration 4 --
|
|
|
|
Deprecated: Invalid characters passed for attempted conversion, these have been ignored in %s on line %d
|
|
int(0)
|
|
|
|
-- Iteration 5 --
|
|
|
|
Deprecated: Invalid characters passed for attempted conversion, these have been ignored in %s on line %d
|
|
int(2)
|
|
|
|
-- Iteration 6 --
|
|
|
|
Deprecated: Invalid characters passed for attempted conversion, these have been ignored in %s on line %d
|
|
int(2)
|
|
|
|
-- Iteration 7 --
|
|
|
|
Deprecated: Invalid characters passed for attempted conversion, these have been ignored in %s on line %d
|
|
int(8)
|
|
|
|
-- Iteration 8 --
|
|
|
|
Deprecated: Invalid characters passed for attempted conversion, these have been ignored in %s on line %d
|
|
int(1)
|
|
|
|
-- Iteration 9 --
|
|
|
|
Deprecated: Invalid characters passed for attempted conversion, these have been ignored in %s on line %d
|
|
int(0)
|
|
|
|
-- Iteration 10 --
|
|
int(1)
|
|
|
|
-- Iteration 11 --
|
|
int(0)
|
|
|
|
-- Iteration 12 --
|
|
int(1)
|
|
|
|
-- Iteration 13 --
|
|
int(0)
|
|
|
|
-- Iteration 14 --
|
|
int(0)
|
|
|
|
-- Iteration 15 --
|
|
int(0)
|
|
|
|
-- Iteration 16 --
|
|
bindec(): Argument #1 ($binary_string) must be of type string, array given
|
|
|
|
-- Iteration 17 --
|
|
|
|
Deprecated: Invalid characters passed for attempted conversion, these have been ignored in %s on line %d
|
|
int(0)
|
|
|
|
-- Iteration 18 --
|
|
|
|
Deprecated: Invalid characters passed for attempted conversion, these have been ignored in %s on line %d
|
|
int(0)
|
|
|
|
-- Iteration 19 --
|
|
|
|
Deprecated: Invalid characters passed for attempted conversion, these have been ignored in %s on line %d
|
|
int(0)
|
|
|
|
-- Iteration 20 --
|
|
bindec(): Argument #1 ($binary_string) must be of type string, resource given
|