1--TEST-- 2Test long2ip() function : usage variation 3--SKIPIF-- 4<?php 5if(substr(PHP_OS, 0, 3) == "WIN") 6 die("skip don't run on Windows"); 7?> 8--FILE-- 9<?php 10/* Prototype : string long2ip(int proper_address) 11 * Description: Converts an (IPv4) Internet network address into a string in Internet standard dotted format 12 * Source code: ext/standard/basic_functions.c 13 * Alias to functions: 14 */ 15 16echo "*** Testing long2ip() : usage variation ***\n"; 17 18// Define error handler 19function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { 20 if (error_reporting() != 0) { 21 // report non-silenced errors 22 echo "Error: $err_no - $err_msg, $filename($linenum)\n"; 23 } 24} 25set_error_handler('test_error_handler'); 26 27// Initialise function arguments not being substituted (if any) 28 29//get an unset variable 30$unset_var = 10; 31unset ($unset_var); 32 33// define some classes 34class classWithToString 35{ 36 public function __toString() { 37 return "Class A object"; 38 } 39} 40 41class classWithoutToString 42{ 43} 44 45// heredoc string 46$heredoc = <<<EOT 47hello world 48EOT; 49 50// add arrays 51$index_array = array (1, 2, 3); 52$assoc_array = array ('one' => 1, 'two' => 2); 53 54// resource 55$res = fopen(__FILE__,'r'); 56 57//array of values to iterate over 58$inputs = array( 59 60 // float data 61 'float 10.5' => 10.5, 62 'float -10.5' => -10.5, 63 'float .5' => .5, 64 65 // array data 66 'empty array' => array(), 67 'int indexed array' => $index_array, 68 'associative array' => $assoc_array, 69 'nested arrays' => array('foo', $index_array, $assoc_array), 70 71 // null data 72 'uppercase NULL' => NULL, 73 'lowercase null' => null, 74 75 // boolean data 76 'lowercase true' => true, 77 'lowercase false' =>false, 78 'uppercase TRUE' =>TRUE, 79 'uppercase FALSE' =>FALSE, 80 81 // empty data 82 'empty string DQ' => "", 83 'empty string SQ' => '', 84 85 // string data 86 'string DQ' => "string", 87 'string SQ' => 'string', 88 'mixed case string' => "sTrInG", 89 'heredoc' => $heredoc, 90 91 // object data 92 'instance of classWithToString' => new classWithToString(), 93 'instance of classWithoutToString' => new classWithoutToString(), 94 95 // undefined data 96 'undefined var' => @$undefined_var, 97 98 // unset data 99 'unset var' => @$unset_var, 100 101 // resource 102 'resource' => $res, 103); 104 105// loop through each element of the array for proper_address 106 107foreach($inputs as $key =>$value) { 108 echo "\n--$key--\n"; 109 var_dump( long2ip($value) ); 110}; 111 112fclose($res); 113 114?> 115===DONE=== 116--EXPECTF-- 117*** Testing long2ip() : usage variation *** 118 119--float 10.5-- 120string(8) "0.0.0.10" 121 122--float -10.5-- 123string(15) "255.255.255.246" 124 125--float .5-- 126string(7) "0.0.0.0" 127 128--empty array-- 129Error: 2 - long2ip() expects parameter 1 to be string, array given, %s(%d) 130NULL 131 132--int indexed array-- 133Error: 2 - long2ip() expects parameter 1 to be string, array given, %s(%d) 134NULL 135 136--associative array-- 137Error: 2 - long2ip() expects parameter 1 to be string, array given, %s(%d) 138NULL 139 140--nested arrays-- 141Error: 2 - long2ip() expects parameter 1 to be string, array given, %s(%d) 142NULL 143 144--uppercase NULL-- 145string(7) "0.0.0.0" 146 147--lowercase null-- 148string(7) "0.0.0.0" 149 150--lowercase true-- 151string(7) "0.0.0.1" 152 153--lowercase false-- 154string(7) "0.0.0.0" 155 156--uppercase TRUE-- 157string(7) "0.0.0.1" 158 159--uppercase FALSE-- 160string(7) "0.0.0.0" 161 162--empty string DQ-- 163string(7) "0.0.0.0" 164 165--empty string SQ-- 166string(7) "0.0.0.0" 167 168--string DQ-- 169string(7) "0.0.0.0" 170 171--string SQ-- 172string(7) "0.0.0.0" 173 174--mixed case string-- 175string(7) "0.0.0.0" 176 177--heredoc-- 178string(7) "0.0.0.0" 179 180--instance of classWithToString-- 181string(7) "0.0.0.0" 182 183--instance of classWithoutToString-- 184Error: 2 - long2ip() expects parameter 1 to be string, object given, %s(%d) 185NULL 186 187--undefined var-- 188string(7) "0.0.0.0" 189 190--unset var-- 191string(7) "0.0.0.0" 192 193--resource-- 194Error: 2 - long2ip() expects parameter 1 to be string, resource given, %s(%d) 195NULL 196===DONE=== 197