1--TEST-- 2Test parse_url() function : usage variations - unexpected type for arg 2. 3--SKIPIF-- 4<?php if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platforms only"); ?> 5--FILE-- 6<?php 7/* Prototype : proto mixed parse_url(string url, [int url_component]) 8 * Description: Parse a URL and return its components 9 * Source code: ext/standard/url.c 10 * Alias to functions: 11 */ 12 13function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { 14 echo "Error: $err_no - $err_msg, $filename($linenum)\n"; 15} 16set_error_handler('test_error_handler'); 17 18echo "*** Testing parse_url() : usage variations ***\n"; 19 20// Initialise function arguments not being substituted (if any) 21$url = 'http://secret:hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123'; 22 23//get an unset variable 24$unset_var = 10; 25unset ($unset_var); 26 27//array of values to iterate over 28$values = array( 29 30 // float data 31 10.5, 32 -10.5, 33 10.1234567e10, 34 10.7654321E-10, 35 .5, 36 37 // array data 38 array(), 39 array(0), 40 array(1), 41 array(1, 2), 42 array('color' => 'red', 'item' => 'pen'), 43 44 // null data 45 NULL, 46 null, 47 48 // boolean data 49 true, 50 false, 51 TRUE, 52 FALSE, 53 54 // empty data 55 "", 56 '', 57 58 // string data 59 "string", 60 'string', 61 62 // object data 63 new stdclass(), 64 65 // undefined data 66 $undefined_var, 67 68 // unset data 69 $unset_var, 70); 71 72// loop through each element of the array for url_component 73 74foreach($values as $value) { 75 echo "\nArg value $value \n"; 76 var_dump( parse_url($url, $value) ); 77}; 78 79echo "Done"; 80?> 81--EXPECTF-- 82*** Testing parse_url() : usage variations *** 83Error: 8 - Undefined variable: undefined_var, %s(%d) 84Error: 8 - Undefined variable: unset_var, %s(%d) 85 86Arg value 10.5 87Error: 2 - parse_url(): Invalid URL component identifier 10, %s(%d) 88bool(false) 89 90Arg value -10.5 91array(8) { 92 ["scheme"]=> 93 string(4) "http" 94 ["host"]=> 95 string(11) "www.php.net" 96 ["port"]=> 97 int(80) 98 ["user"]=> 99 string(6) "secret" 100 ["pass"]=> 101 string(7) "hideout" 102 ["path"]=> 103 string(10) "/index.php" 104 ["query"]=> 105 string(31) "test=1&test2=char&test3=mixesCI" 106 ["fragment"]=> 107 string(16) "some_page_ref123" 108} 109 110Arg value 101234567000 111Error: 2 - parse_url() expects parameter 2 to be int, float given, %s(%d) 112NULL 113 114Arg value 1.07654321E-9 115string(4) "http" 116 117Arg value 0.5 118string(4) "http" 119Error: 8 - Array to string conversion, %s(%d) 120 121Arg value Array 122Error: 2 - parse_url() expects parameter 2 to be int, array given, %s(%d) 123NULL 124Error: 8 - Array to string conversion, %s(%d) 125 126Arg value Array 127Error: 2 - parse_url() expects parameter 2 to be int, array given, %s(%d) 128NULL 129Error: 8 - Array to string conversion, %s(%d) 130 131Arg value Array 132Error: 2 - parse_url() expects parameter 2 to be int, array given, %s(%d) 133NULL 134Error: 8 - Array to string conversion, %s(%d) 135 136Arg value Array 137Error: 2 - parse_url() expects parameter 2 to be int, array given, %s(%d) 138NULL 139Error: 8 - Array to string conversion, %s(%d) 140 141Arg value Array 142Error: 2 - parse_url() expects parameter 2 to be int, array given, %s(%d) 143NULL 144 145Arg value 146string(4) "http" 147 148Arg value 149string(4) "http" 150 151Arg value 1 152string(%d) "www.php.net" 153 154Arg value 155string(4) "http" 156 157Arg value 1 158string(%d) "www.php.net" 159 160Arg value 161string(4) "http" 162 163Arg value 164Error: 2 - parse_url() expects parameter 2 to be int, string given, %s(%d) 165NULL 166 167Arg value 168Error: 2 - parse_url() expects parameter 2 to be int, string given, %s(%d) 169NULL 170 171Arg value string 172Error: 2 - parse_url() expects parameter 2 to be int, string given, %s(%d) 173NULL 174 175Arg value string 176Error: 2 - parse_url() expects parameter 2 to be int, string given, %s(%d) 177NULL 178Error: 4096 - Object of class stdClass could not be converted to string, %s(%d) 179 180Arg value 181Error: 2 - parse_url() expects parameter 2 to be int, object given, %s(%d) 182NULL 183 184Arg value 185string(4) "http" 186 187Arg value 188string(4) "http" 189Done 190