1--TEST-- 2Interface of the class mysqli 3--SKIPIF-- 4<?php 5require_once('skipif.inc'); 6require_once('skipifemb.inc'); 7require_once('skipifconnectfailure.inc'); 8?> 9--FILE-- 10<?php 11 require('connect.inc'); 12 13 $mysqli = new mysqli($host, $user, $passwd, $db, $port, $socket); 14 $link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket); 15 16 printf("Parent class:\n"); 17 var_dump(get_parent_class($mysqli)); 18 19 printf("\nMethods:\n"); 20 $methods = get_class_methods($mysqli); 21 $expected_methods = array( 22 'autocommit' => true, 23 'change_user' => true, 24 'character_set_name' => true, 25 'close' => true, 26 'commit' => true, 27 'connect' => true, 28 'dump_debug_info' => true, 29 'escape_string' => true, 30 'get_charset' => true, 31 'get_client_info' => true, 32 'get_server_info' => true, 33 'get_warnings' => true, 34 'init' => true, 35 'kill' => true, 36 'more_results' => true, 37 'multi_query' => true, 38 'mysqli' => true, 39 'next_result' => true, 40 'options' => true, 41 'ping' => true, 42 'prepare' => true, 43 'query' => true, 44 'real_connect' => true, 45 'real_escape_string' => true, 46 'real_query' => true, 47 'refresh' => true, 48 'rollback' => true, 49 'select_db' => true, 50 'set_charset' => true, 51 'set_opt' => true, 52 'ssl_set' => true, 53 'stat' => true, 54 'stmt_init' => true, 55 'store_result' => true, 56 'thread_safe' => true, 57 'use_result' => true, 58 ); 59 60 if (version_compare(PHP_VERSION, '5.3.99', '<=')) { 61 $expected_methods['client_encoding'] = true; 62 } 63 64 if ($IS_MYSQLND) { 65 // mysqlnd only 66 /* $expected_methods['get_client_stats'] = true; */ 67 $expected_methods['get_connection_stats'] = true; 68 $expected_methods['reap_async_query'] = true; 69 $expected_methods['poll'] = true; 70 } else { 71 // libmysql only 72 if (function_exists('mysqli_ssl_set')) 73 $expected_methods['ssl_set'] = true; 74 $expected_methods['set_local_infile_default'] = true; 75 $expected_methods['set_local_infile_handler'] = true; 76 } 77 78 /* we should add ruled when to expect them */ 79 if (function_exists('mysqli_debug')) 80 $expected_methods['debug'] = true; 81 if (function_exists('ssl_set')) 82 $expected_methods['ssl_set'] = true; 83 84 foreach ($methods as $k => $method) { 85 if (isset($expected_methods[$method])) { 86 unset($methods[$k]); 87 unset($expected_methods[$method]); 88 } 89 } 90 if (!empty($methods)) { 91 printf("Dumping list of unexpected methods.\n"); 92 var_dump($methods); 93 } 94 if (!empty($expected_methods)) { 95 printf("Dumping list of missing methods.\n"); 96 var_dump($expected_methods); 97 } 98 if (empty($methods) && empty($expected_methods)) 99 printf("ok\n"); 100 101 printf("\nClass variables:\n"); 102 103 $expected_class_variables = $expected_object_variables = array( 104 "affected_rows" => true, 105 "client_info" => true, 106 "client_version" => true, 107 "connect_errno" => true, 108 "connect_error" => true, 109 "errno" => true, 110 "error" => true, 111 "field_count" => true, 112 "host_info" => true, 113 "info" => true, 114 "insert_id" => true, 115 "protocol_version" => true, 116 "server_info" => true, 117 "server_version" => true, 118 "sqlstate" => true, 119 "stat" => true, 120 "thread_id" => true, 121 "warning_count" => true, 122 ); 123 124 if (version_compare(PHP_VERSION, '5.3.99', '>')) { 125 $expected_class_variables["error_list"] = true; 126 $expected_object_variables["error_list"] = true; 127 } 128 129 $variables = get_class_vars(get_class($mysqli)); 130 foreach ($variables as $var => $v) { 131 if (isset($expected_class_variables[$var])) { 132 unset($expected_class_variables[$var]); 133 unset($variables[$var]); 134 } 135 } 136 137 if (!empty($expected_class_variables)) { 138 printf("Dumping list of missing class variables\n"); 139 var_dump($expected_class_variables); 140 } 141 if (!empty($variables)) { 142 printf("Dumping list of unexpected class variables\n"); 143 var_dump($variables); 144 } 145 echo "ok\n"; 146 147 printf("\nObject variables:\n"); 148 $variables = get_object_vars($mysqli); 149 foreach ($variables as $var => $v) { 150 if (isset($expected_object_variables[$var])) { 151 unset($expected_object_variables[$var]); 152 unset($variables[$var]); 153 } 154 } 155 156 if (!empty($expected_object_variables)) { 157 printf("Dumping list of missing object variables\n"); 158 var_dump($expected_object_variables); 159 } 160 if (!empty($variables)) { 161 printf("Dumping list of unexpected object variables\n"); 162 var_dump($variables); 163 } 164 echo "ok\n"; 165 166 167 printf("\nMagic, magic properties:\n"); 168 169 assert(mysqli_affected_rows($link) === $mysqli->affected_rows); 170 printf("mysqli->affected_rows = '%s'/%s ('%s'/%s)\n", 171 $mysqli->affected_rows, gettype($mysqli->affected_rows), 172 mysqli_affected_rows($link), gettype(mysqli_affected_rows($link))); 173 174 assert(mysqli_get_client_info() === $mysqli->client_info); 175 printf("mysqli->client_info = '%s'/%s ('%s'/%s)\n", 176 $mysqli->client_info, gettype($mysqli->client_info), 177 mysqli_get_client_info(), gettype(mysqli_get_client_info())); 178 179 assert(mysqli_get_client_version() === $mysqli->client_version); 180 printf("mysqli->client_version = '%s'/%s ('%s'/%s)\n", 181 $mysqli->client_version, gettype($mysqli->client_version), 182 mysqli_get_client_version(), gettype(mysqli_get_client_version())); 183 184 assert(mysqli_errno($link) === $mysqli->errno); 185 printf("mysqli->errno = '%s'/%s ('%s'/%s)\n", 186 $mysqli->errno, gettype($mysqli->errno), 187 mysqli_errno($link), gettype(mysqli_errno($link))); 188 189 assert(mysqli_error($link) === $mysqli->error); 190 printf("mysqli->error = '%s'/%s ('%s'/%s)\n", 191 $mysqli->error, gettype($mysqli->error), 192 mysqli_error($link), gettype(mysqli_error($link))); 193 194 if (version_compare(PHP_VERSION, '5.3.99', '>')) { 195 assert(mysqli_error_list($link) === $mysqli->error_list); 196 assert(is_array($mysqli->error_list)); 197 } 198 199 assert(mysqli_field_count($link) === $mysqli->field_count); 200 printf("mysqli->field_count = '%s'/%s ('%s'/%s)\n", 201 $mysqli->field_count, gettype($mysqli->field_count), 202 mysqli_field_count($link), gettype(mysqli_field_count($link))); 203 204 assert(mysqli_insert_id($link) === $mysqli->insert_id); 205 printf("mysqli->insert_id = '%s'/%s ('%s'/%s)\n", 206 $mysqli->insert_id, gettype($mysqli->insert_id), 207 mysqli_insert_id($link), gettype(mysqli_insert_id($link))); 208 209 assert(mysqli_sqlstate($link) === $mysqli->sqlstate); 210 printf("mysqli->sqlstate = '%s'/%s ('%s'/%s)\n", 211 $mysqli->sqlstate, gettype($mysqli->sqlstate), 212 mysqli_sqlstate($link), gettype(mysqli_sqlstate($link))); 213 214 assert(soundex(mysqli_stat($link)) == soundex($mysqli->stat)); 215 printf("mysqli->stat = '%s'/%s ('%s'/%s)\n", 216 $mysqli->stat, gettype($mysqli->stat), 217 mysqli_stat($link), gettype(mysqli_stat($link))); 218 219 assert(mysqli_get_host_info($link) === $mysqli->host_info); 220 printf("mysqli->host_info = '%s'/%s ('%s'/%s)\n", 221 $mysqli->host_info, gettype($mysqli->host_info), 222 mysqli_get_host_info($link), gettype(mysqli_get_host_info($link))); 223 224 /* note that the data types are different */ 225 assert(mysqli_info($link) == $mysqli->info); 226 printf("mysqli->info = '%s'/%s ('%s'/%s)\n", 227 $mysqli->info, gettype($mysqli->info), 228 mysqli_info($link), gettype(mysqli_info($link))); 229 230 assert(mysqli_thread_id($link) > $mysqli->thread_id); 231 assert(gettype($mysqli->thread_id) == gettype(mysqli_thread_id($link))); 232 printf("mysqli->thread_id = '%s'/%s ('%s'/%s)\n", 233 $mysqli->thread_id, gettype($mysqli->thread_id), 234 mysqli_thread_id($link), gettype(mysqli_thread_id($link))); 235 236 assert(mysqli_get_proto_info($link) === $mysqli->protocol_version); 237 printf("mysqli->protocol_version = '%s'/%s ('%s'/%s)\n", 238 $mysqli->protocol_version, gettype($mysqli->protocol_version), 239 mysqli_get_proto_info($link), gettype(mysqli_get_proto_info($link))); 240 241 assert(mysqli_get_server_info($link) === $mysqli->server_info); 242 printf("mysqli->server_info = '%s'/%s ('%s'/%s)\n", 243 $mysqli->server_info, gettype($mysqli->server_info), 244 mysqli_get_server_info($link), gettype(mysqli_get_server_info($link))); 245 246 assert(mysqli_get_server_version($link) === $mysqli->server_version); 247 printf("mysqli->server_version = '%s'/%s ('%s'/%s)\n", 248 $mysqli->server_version, gettype($mysqli->server_version), 249 mysqli_get_server_version($link), gettype(mysqli_get_server_version($link))); 250 251 assert(mysqli_warning_count($link) === $mysqli->warning_count); 252 printf("mysqli->warning_count = '%s'/%s ('%s'/%s)\n", 253 $mysqli->warning_count, gettype($mysqli->warning_count), 254 mysqli_warning_count($link), gettype(mysqli_warning_count($link))); 255 256 printf("\nAccess to undefined properties:\n"); 257 printf("mysqli->unknown = '%s'\n", @$mysqli->unknown); 258 259 @$mysqli->unknown = 13; 260 printf("setting mysqli->unknown, mysqli_unknown = '%s'\n", @$mysqli->unknown); 261 262 $unknown = 'friday'; 263 @$mysqli->unknown = $unknown; 264 printf("setting mysqli->unknown, mysqli_unknown = '%s'\n", @$mysqli->unknown); 265 266 $mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket); 267 printf("\nAccess hidden properties for MYSLQI_STATUS_INITIALIZED (TODO documentation):\n"); 268 assert(mysqli_connect_error() === $mysqli->connect_error); 269 printf("mysqli->connect_error = '%s'/%s ('%s'/%s)\n", 270 $mysqli->connect_error, gettype($mysqli->connect_error), 271 mysqli_connect_error(), gettype(mysqli_connect_error())); 272 273 assert(mysqli_connect_errno() === $mysqli->connect_errno); 274 printf("mysqli->connect_errno = '%s'/%s ('%s'/%s)\n", 275 $mysqli->connect_errno, gettype($mysqli->connect_errno), 276 mysqli_connect_errno(), gettype(mysqli_connect_errno())); 277 278 print "done!"; 279?> 280--EXPECTF-- 281Parent class: 282bool(false) 283 284Methods: 285ok 286 287Class variables: 288ok 289 290Object variables: 291ok 292 293Magic, magic properties: 294mysqli->affected_rows = '%s'/integer ('%s'/integer) 295mysqli->client_info = '%s'/%unicode|string% ('%s'/%unicode|string%) 296mysqli->client_version = '%d'/integer ('%d'/integer) 297mysqli->errno = '0'/integer ('0'/integer) 298mysqli->error = ''/%unicode|string% (''/%unicode|string%) 299mysqli->field_count = '0'/integer ('0'/integer) 300mysqli->insert_id = '0'/integer ('0'/integer) 301mysqli->sqlstate = '00000'/%unicode|string% ('00000'/%unicode|string%) 302mysqli->stat = 'Uptime: %d Threads: %d Questions: %d Slow queries: %d Opens: %d Flush tables: %d Open tables: %d Queries per second avg: %d.%d'/string ('Uptime: %d Threads: %d Questions: %d Slow queries: %d Opens: %d Flush tables: %d Open tables: %d Queries per second avg: %d.%d'/string) 303mysqli->host_info = '%s'/%unicode|string% ('%s'/%unicode|string%) 304mysqli->info = ''/NULL (''/%unicode|string%) 305mysqli->thread_id = '%d'/integer ('%d'/integer) 306mysqli->protocol_version = '%d'/integer ('%d'/integer) 307mysqli->server_info = '%s'/%unicode|string% ('%s'/%unicode|string%) 308mysqli->server_version = '%d'/integer ('%d'/integer) 309mysqli->warning_count = '0'/integer ('0'/integer) 310 311Access to undefined properties: 312mysqli->unknown = '' 313setting mysqli->unknown, mysqli_unknown = '13' 314setting mysqli->unknown, mysqli_unknown = 'friday' 315 316Access hidden properties for MYSLQI_STATUS_INITIALIZED (TODO documentation): 317mysqli->connect_error = ''/NULL (''/NULL) 318mysqli->connect_errno = '0'/integer ('0'/integer) 319done!