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