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