array_pad_variation2.phpt [plain text]
--TEST--
Test array_pad() function : usage variations - unexpected values for 'pad_size' argument(Bug#43482)
--FILE--
<?php
echo "*** Testing array_pad() : passing non integer values to \$pad_size argument ***\n";
$input = array(1, 2);
$pad_value = 1;
$unset_var = 10;
unset ($unset_var);
class classA
{
public function __toString() {
return "Class A object";
}
}
$pad_sizes = array(
10.5,
-10.5,
12.3456789000e10,
-12.3456789000e10,
12.3456789000E-10,
.5,
array(),
array(0),
array(1),
array(1, 2),
array('color' => 'red', 'item' => 'pen'),
NULL,
null,
true,
false,
TRUE,
FALSE,
"",
'',
"string",
'string',
new classA(),
@$undefined_var,
@$unset_var,
);
$iterator = 1;
foreach($pad_sizes as $pad_size) {
echo "-- Iteration $iterator --\n";
var_dump( array_pad($input, $pad_size, $pad_value) );
$iterator++;
};
echo "Done";
?>
--EXPECTF--
*** Testing array_pad() : passing non integer values to $pad_size argument ***
-- Iteration 1 --
array(10) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(1)
[3]=>
int(1)
[4]=>
int(1)
[5]=>
int(1)
[6]=>
int(1)
[7]=>
int(1)
[8]=>
int(1)
[9]=>
int(1)
}
-- Iteration 2 --
array(10) {
[0]=>
int(1)
[1]=>
int(1)
[2]=>
int(1)
[3]=>
int(1)
[4]=>
int(1)
[5]=>
int(1)
[6]=>
int(1)
[7]=>
int(1)
[8]=>
int(1)
[9]=>
int(2)
}
-- Iteration 3 --
Warning: array_pad(): You may only pad up to 1048576 elements at a time in %s on line %d
bool(false)
-- Iteration 4 --
Warning: array_pad(): You may only pad up to 1048576 elements at a time in %s on line %d
bool(false)
-- Iteration 5 --
array(2) {
[0]=>
int(1)
[1]=>
int(2)
}
-- Iteration 6 --
array(2) {
[0]=>
int(1)
[1]=>
int(2)
}
-- Iteration 7 --
Warning: array_pad() expects parameter 2 to be long, array given in %s on line %d
NULL
-- Iteration 8 --
Warning: array_pad() expects parameter 2 to be long, array given in %s on line %d
NULL
-- Iteration 9 --
Warning: array_pad() expects parameter 2 to be long, array given in %s on line %d
NULL
-- Iteration 10 --
Warning: array_pad() expects parameter 2 to be long, array given in %s on line %d
NULL
-- Iteration 11 --
Warning: array_pad() expects parameter 2 to be long, array given in %s on line %d
NULL
-- Iteration 12 --
array(2) {
[0]=>
int(1)
[1]=>
int(2)
}
-- Iteration 13 --
array(2) {
[0]=>
int(1)
[1]=>
int(2)
}
-- Iteration 14 --
array(2) {
[0]=>
int(1)
[1]=>
int(2)
}
-- Iteration 15 --
array(2) {
[0]=>
int(1)
[1]=>
int(2)
}
-- Iteration 16 --
array(2) {
[0]=>
int(1)
[1]=>
int(2)
}
-- Iteration 17 --
array(2) {
[0]=>
int(1)
[1]=>
int(2)
}
-- Iteration 18 --
Warning: array_pad() expects parameter 2 to be long, string given in %s on line %d
NULL
-- Iteration 19 --
Warning: array_pad() expects parameter 2 to be long, string given in %s on line %d
NULL
-- Iteration 20 --
Warning: array_pad() expects parameter 2 to be long, string given in %s on line %d
NULL
-- Iteration 21 --
Warning: array_pad() expects parameter 2 to be long, string given in %s on line %d
NULL
-- Iteration 22 --
Warning: array_pad() expects parameter 2 to be long, object given in %s on line %d
NULL
-- Iteration 23 --
array(2) {
[0]=>
int(1)
[1]=>
int(2)
}
-- Iteration 24 --
array(2) {
[0]=>
int(1)
[1]=>
int(2)
}
Done