1--TEST-- 2Test ip2long() function : usage variation 3--SKIPIF-- 4<?php 5if(substr(PHP_OS, 0, 3) == "WIN") 6 die("skip. Windows is more compliant (like 0 for localhost, etc.)"); 7?> 8--FILE-- 9<?php 10/* Prototype : int ip2long(string ip_address) 11 * Description: Converts a string containing an (IPv4) Internet Protocol dotted address into a proper address 12 * Source code: ext/standard/basic_functions.c 13 * Alias to functions: 14 */ 15 16echo "*** Testing ip2long() : 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 // int data 61 'int 0' => 0, 62 'int 1' => 1, 63 'int 12345' => 12345, 64 'int -12345' => -2345, 65 66 // float data 67 'float 10.5' => 10.5, 68 'float -10.5' => -10.5, 69 'float 12.3456789000e10' => 12.3456789000e10, 70 'float -12.3456789000e10' => -12.3456789000e10, 71 'float .5' => .5, 72 73 // array data 74 'empty array' => array(), 75 'int indexed array' => $index_array, 76 'associative array' => $assoc_array, 77 'nested arrays' => array('foo', $index_array, $assoc_array), 78 79 // null data 80 'uppercase NULL' => NULL, 81 'lowercase null' => null, 82 83 // boolean data 84 'lowercase true' => true, 85 'lowercase false' =>false, 86 'uppercase TRUE' =>TRUE, 87 'uppercase FALSE' =>FALSE, 88 89 // empty data 90 'empty string DQ' => "", 91 'empty string SQ' => '', 92 93 // object data 94 'instance of classWithToString' => new classWithToString(), 95 'instance of classWithoutToString' => new classWithoutToString(), 96 97 // undefined data 98 'undefined var' => @$undefined_var, 99 100 // unset data 101 'unset var' => @$unset_var, 102 103 // resource 104 'resource' => $res, 105); 106 107// loop through each element of the array for ip_address 108 109foreach($inputs as $key =>$value) { 110 echo "\n--$key--\n"; 111 var_dump( ip2long($value) ); 112}; 113 114fclose($res); 115 116?> 117===DONE=== 118--EXPECTF-- 119*** Testing ip2long() : usage variation *** 120 121--int 0-- 122bool(false) 123 124--int 1-- 125bool(false) 126 127--int 12345-- 128bool(false) 129 130--int -12345-- 131bool(false) 132 133--float 10.5-- 134bool(false) 135 136--float -10.5-- 137bool(false) 138 139--float 12.3456789000e10-- 140bool(false) 141 142--float -12.3456789000e10-- 143bool(false) 144 145--float .5-- 146bool(false) 147 148--empty array-- 149Error: 2 - ip2long() expects parameter 1 to be string, array given, %s(%d) 150NULL 151 152--int indexed array-- 153Error: 2 - ip2long() expects parameter 1 to be string, array given, %s(%d) 154NULL 155 156--associative array-- 157Error: 2 - ip2long() expects parameter 1 to be string, array given, %s(%d) 158NULL 159 160--nested arrays-- 161Error: 2 - ip2long() expects parameter 1 to be string, array given, %s(%d) 162NULL 163 164--uppercase NULL-- 165bool(false) 166 167--lowercase null-- 168bool(false) 169 170--lowercase true-- 171bool(false) 172 173--lowercase false-- 174bool(false) 175 176--uppercase TRUE-- 177bool(false) 178 179--uppercase FALSE-- 180bool(false) 181 182--empty string DQ-- 183bool(false) 184 185--empty string SQ-- 186bool(false) 187 188--instance of classWithToString-- 189bool(false) 190 191--instance of classWithoutToString-- 192Error: 2 - ip2long() expects parameter 1 to be string, object given, %s(%d) 193NULL 194 195--undefined var-- 196bool(false) 197 198--unset var-- 199bool(false) 200 201--resource-- 202Error: 2 - ip2long() expects parameter 1 to be string, resource given, %s(%d) 203NULL 204===DONE=== 205