var_dump_64bit.phpt [plain text]
--TEST--
Test var_dump() function
--SKIPIF--
<?php
if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
?>
--INI--
precision=14
--FILE--
<?php
function check_vardump( $variables ) {
$counter = 1;
foreach( $variables as $variable ) {
echo "-- Iteration $counter --\n";
var_dump($variable);
$counter++;
}
}
echo "\n*** Testing var_dump() on integer variables ***\n";
$integers = array (
0, 000000123, 123000000,
-00000123, -12300000,
range(1,10), range(-1,-10), +2147483647, +2147483648, -2147483648, -2147483647, 0x7FFFFFFF, -0x80000000, 017777777777, -020000000000 );
check_vardump($integers);
echo "\n*** Testing var_dump() on float variables ***\n";
$floats = array (
-0.0,
+0.0,
1.234,
-1.234,
-2.000000,
000002.00,
-.5,
.567,
-.6700000e-3,
-.6700000E+3,
.6700000E+3,
.6700000e+3,
-4.10003e-3,
-4.10003E+3,
4.100003e-3,
4.100003E+3,
1e5,
-1e5,
1e-5,
-1e-5,
1e+5,
-1e+5,
1E5,
-1E5,
1E+5,
-1E+5,
1E-5,
-1E-5,
-0x80000001, 0x80000001, 020000000001, -020000000001 );
check_vardump($floats);
echo "\n*** Testing var_dump() on string variables ***\n";
$strings = array (
"",
'',
" ",
' ',
"0",
"\0",
'\0',
"\t",
'\t',
"PHP",
'PHP',
"abcd\x0n1234\x0005678\x0000efgh\xijkl", "abcd\0efgh\0ijkl\x00mnop\x000qrst\00uvwx\0000yz", "1234\t\n5678\n\t9100\rabcda" );
check_vardump($strings);
echo "\n*** Testing var_dump() on boolean variables ***\n";
$booleans = array (
TRUE,
FALSE,
true,
false
);
check_vardump($booleans);
echo "\n*** Testing var_dump() on array variables ***\n";
$arrays = array (
array(),
array(NULL),
array(null),
array(true),
array(""),
array(''),
array(array(), array()),
array(array(1, 2), array('a', 'b')),
array(1 => 'One'),
array("test" => "is_array"),
array(0),
array(-1),
array(10.5, 5.6),
array("string", "test"),
array('string', 'test'),
);
check_vardump($arrays);
echo "\n*** Testing var_dump() on object variables ***\n";
class object_class
{
var $value;
public $public_var1 = 10;
private $private_var1 = 20;
private $private_var2;
protected $protected_var1 = "string_1";
protected $protected_var2;
function object_class ( ) {
$this->value = 50;
$this->public_var2 = 11;
$this->private_var2 = 21;
$this->protected_var2 = "string_2";
}
public function foo1() {
echo "foo1() is called\n";
}
protected function foo2() {
echo "foo2() is called\n";
}
private function foo3() {
echo "foo3() is called\n";
}
}
class no_member_class {
}
class contains_object_class
{
var $p = 30;
var $class_object1;
public $class_object2;
private $class_object3;
protected $class_object4;
var $no_member_class_object;
public function func() {
echo "func() is called \n";
}
function contains_object_class () {
$this->class_object1 = new object_class();
$this->class_object2 = new object_class();
$this->class_object3 = $this->class_object1;
$this->class_object4 = $this->class_object2;
$this->no_member_class_object = new no_member_class();
$this->class_object5 = $this; }
}
$obj = new contains_object_class;
$temp_class_obj = new object_class();
$unset_obj = new object_class();
unset($unset_obj);
$objects = array (
new object_class,
new no_member_class,
new contains_object_class,
$obj,
$obj->class_object1,
$obj->class_object2,
$obj->no_member_class_object,
$temp_class_obj,
@$unset_obj
);
check_vardump($objects);
echo "\n** Testing var_dump() on objects having circular reference **\n";
$recursion_obj1 = new object_class();
$recursion_obj2 = new object_class();
$recursion_obj1->obj = &$recursion_obj2; $recursion_obj2->obj = &$recursion_obj1; var_dump($recursion_obj2);
echo "\n*** Testing var_dump() on resources ***\n";
$file_handle = fopen(__FILE__, "r");
$dir_handle = opendir( dirname(__FILE__) );
$resources = array (
$file_handle,
$dir_handle
);
check_vardump($resources);
echo "\n*** Testing var_dump() on different combinations of scalar
and non-scalar variables ***\n";
$unset_var = 10.5;
unset($unset_var);
unset($file_handle);
$variations = array (
array( 123, -1.2345, "a" ),
array( "d", array(1, 3, 5), true, null),
array( new no_member_class, array(), false, 0 ),
array( -0.00, "Where am I?", array(7,8,9), TRUE, 'A', 987654321 ),
array( @$unset_var, 2.E+10, 100-20.9, 000004.599998 ), array( "array(1,2,3,4)1.0000002TRUE", @$file_handle, 111333.00+45e5, '/00\7')
);
check_vardump($variations);
echo "\n*** Testing var_dump() on miscelleneous input arguments ***\n";
$misc_values = array (
@$unset_var,
NULL, @$undef_variable, null
);
check_vardump($misc_values);
echo "\n*** Testing var_dump() on multiple arguments ***\n";
var_dump( $integers, $floats, $strings, $arrays, $booleans, $resources,
$objects, $misc_values, $variations );
echo "\n*** Testing var_dump() on anonymous functions ***\n";
$newfunc = create_function('$a,$b', 'return "$a * $b = " . ($a * $b);');
echo "New anonymous function: $newfunc\n";
var_dump( $newfunc(2, 3) );
var_dump( create_function('$a', 'return "$a * $a = " . ($a * $b);') );
echo "\n*** Testing error conditions ***\n";
var_dump();
closedir($dir_handle);
echo "Done\n";
?>
--EXPECTF--
*** Testing var_dump() on integer variables ***
-- Iteration 1 --
int(0)
-- Iteration 2 --
int(83)
-- Iteration 3 --
int(123000000)
-- Iteration 4 --
int(-83)
-- Iteration 5 --
int(-12300000)
-- Iteration 6 --
array(10) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
[3]=>
int(4)
[4]=>
int(5)
[5]=>
int(6)
[6]=>
int(7)
[7]=>
int(8)
[8]=>
int(9)
[9]=>
int(10)
}
-- Iteration 7 --
array(10) {
[0]=>
int(-1)
[1]=>
int(-2)
[2]=>
int(-3)
[3]=>
int(-4)
[4]=>
int(-5)
[5]=>
int(-6)
[6]=>
int(-7)
[7]=>
int(-8)
[8]=>
int(-9)
[9]=>
int(-10)
}
-- Iteration 8 --
int(2147483647)
-- Iteration 9 --
int(2147483648)
-- Iteration 10 --
int(-2147483648)
-- Iteration 11 --
int(-2147483647)
-- Iteration 12 --
int(2147483647)
-- Iteration 13 --
int(-2147483648)
-- Iteration 14 --
int(2147483647)
-- Iteration 15 --
int(-2147483648)
*** Testing var_dump() on float variables ***
-- Iteration 1 --
float(0)
-- Iteration 2 --
float(0)
-- Iteration 3 --
float(1.234)
-- Iteration 4 --
float(-1.234)
-- Iteration 5 --
float(-2)
-- Iteration 6 --
float(2)
-- Iteration 7 --
float(-0.5)
-- Iteration 8 --
float(0.567)
-- Iteration 9 --
float(-0.00067)
-- Iteration 10 --
float(-670)
-- Iteration 11 --
float(670)
-- Iteration 12 --
float(670)
-- Iteration 13 --
float(-0.00410003)
-- Iteration 14 --
float(-4100.03)
-- Iteration 15 --
float(0.004100003)
-- Iteration 16 --
float(4100.003)
-- Iteration 17 --
float(100000)
-- Iteration 18 --
float(-100000)
-- Iteration 19 --
float(1.0E-5)
-- Iteration 20 --
float(-1.0E-5)
-- Iteration 21 --
float(100000)
-- Iteration 22 --
float(-100000)
-- Iteration 23 --
float(100000)
-- Iteration 24 --
float(-100000)
-- Iteration 25 --
float(100000)
-- Iteration 26 --
float(-100000)
-- Iteration 27 --
float(1.0E-5)
-- Iteration 28 --
float(-1.0E-5)
-- Iteration 29 --
int(-2147483649)
-- Iteration 30 --
int(2147483649)
-- Iteration 31 --
int(2147483649)
-- Iteration 32 --
int(-2147483649)
*** Testing var_dump() on string variables ***
-- Iteration 1 --
string(0) ""
-- Iteration 2 --
string(0) ""
-- Iteration 3 --
string(1) " "
-- Iteration 4 --
string(1) " "
-- Iteration 5 --
string(1) "0"
-- Iteration 6 --
string(1) "