1--TEST-- 2Interface of the class mysqli_stmt 3--SKIPIF-- 4<?php 5 require_once('skipif.inc'); 6 require_once('skipifconnectfailure.inc'); 7?> 8--FILE-- 9<?php 10 require('connect.inc'); 11 require('table.inc'); 12 13 $link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket); 14 $stmt = new mysqli_stmt($link); 15 16 printf("Parent class:\n"); 17 var_dump(get_parent_class($stmt)); 18 19 printf("\nMethods:\n"); 20 21 $methods = get_class_methods($stmt); 22 $expected_methods = array( 23 '__construct' => true, 24 'attr_get' => true, 25 'attr_set' => true, 26 'bind_param' => true, 27 'bind_result' => true, 28 'close' => true, 29 'data_seek' => true, 30 'execute' => true, 31 'fetch' => true, 32 'free_result' => true, 33 'get_warnings' => true, 34 'num_rows' => true, 35 'prepare' => true, 36 'reset' => true, 37 'result_metadata' => true, 38 'send_long_data' => true, 39 'store_result' => true, 40 ); 41 42 if ($IS_MYSQLND) { 43 $expected_methods['get_result'] = true; 44 $expected_methods['more_results'] = true; 45 $expected_methods['next_result'] = true; 46 } 47 48 foreach ($methods as $k => $method) { 49 if (isset($expected_methods[$method])) { 50 unset($methods[$k]); 51 unset($expected_methods[$method]); 52 } 53 if ($method == 'mysqli_stmt') { 54 // get_class_method reports different constructor names 55 unset($expected_methods['__construct']); 56 unset($methods[$k]); 57 } 58 } 59 if (!empty($methods)) { 60 printf("More methods found than indicated. Dumping list of unexpected methods.\n"); 61 var_dump($methods); 62 } 63 if (!empty($expected_methods)) { 64 printf("Some methods are missing. Dumping list of missing methods.\n"); 65 var_dump($expected_methods); 66 } 67 if (empty($methods) && empty($expected_methods)) 68 printf("ok\n"); 69 70 printf("\nClass variables:\n"); 71 $variables = array_keys(get_class_vars(get_class($stmt))); 72 sort($variables); 73 foreach ($variables as $k => $var) 74 printf("%s\n", $var); 75 76 printf("\nObject variables:\n"); 77 $variables = array_keys(get_object_vars($stmt)); 78 foreach ($variables as $k => $var) 79 printf("%s\n", $var); 80 81printf("\nMagic, magic properties:\n"); 82 83try { 84 mysqli_stmt_affected_rows($stmt); 85} catch (Error $exception) { 86 echo $exception->getMessage() . "\n"; 87} 88 89try { 90 $stmt->affected_rows; 91} catch (Error $exception) { 92 echo $exception->getMessage() . "\n"; 93} 94 95if (!$stmt->prepare("INSERT INTO test(id, label) VALUES (100, 'z')") || !$stmt->execute()) { 96 printf("[001] [%d] %s\n", $stmt->errno, $stmt->error); 97} 98 99assert(mysqli_stmt_affected_rows($stmt) === $stmt->affected_rows); 100printf("stmt->affected_rows = '%s'\n", $stmt->affected_rows); 101 102assert(mysqli_stmt_errno($stmt) === $stmt->errno); 103printf("stmt->errno = '%s'\n", $stmt->errno); 104 105assert(mysqli_stmt_error($stmt) === $stmt->error); 106printf("stmt->error = '%s'\n", $stmt->error); 107 108assert(mysqli_stmt_error_list($stmt) === $stmt->error_list); 109var_dump("stmt->error = ", $stmt->error_list); 110 111assert(mysqli_stmt_field_count($stmt) === $stmt->field_count); 112printf("stmt->field_count = '%s'\n", $stmt->field_count); 113 114assert($stmt->id > 0); 115printf("stmt->id = '%s'\n", $stmt->id); 116 117assert(mysqli_stmt_insert_id($stmt) === $stmt->insert_id); 118printf("stmt->insert_id = '%s'\n", $stmt->insert_id); 119 120assert(mysqli_stmt_num_rows($stmt) === $stmt->num_rows); 121printf("stmt->num_rows = '%s'\n", $stmt->num_rows); 122 123assert(mysqli_stmt_param_count($stmt) === $stmt->param_count); 124printf("stmt->param_count = '%s'\n", $stmt->param_count); 125 126assert(mysqli_stmt_sqlstate($stmt) === $stmt->sqlstate); 127printf("stmt->sqlstate = '%s'\n", $stmt->sqlstate); 128 129printf("\nAccess to undefined properties:\n"); 130printf("stmt->unknown = '%s'\n", @$stmt->unknown); 131@$stmt->unknown = 13; 132printf("stmt->unknown = '%s'\n", @$stmt->unknown); 133 134print "done!"; 135?> 136--EXPECTF-- 137Parent class: 138bool(false) 139 140Methods: 141ok 142 143Class variables: 144affected_rows 145errno 146error 147error_list 148field_count 149id 150insert_id 151num_rows 152param_count 153sqlstate 154 155Object variables: 156affected_rows 157insert_id 158num_rows 159param_count 160field_count 161errno 162error 163error_list 164sqlstate 165id 166 167Magic, magic properties: 168mysqli_stmt object is not fully initialized 169Property access is not allowed yet 170stmt->affected_rows = '1' 171stmt->errno = '0' 172stmt->error = '' 173string(14) "stmt->error = " 174array(0) { 175} 176stmt->field_count = '0' 177stmt->id = '%d' 178stmt->insert_id = '0' 179stmt->num_rows = '0' 180stmt->param_count = '0' 181stmt->sqlstate = '00000' 182 183Access to undefined properties: 184stmt->unknown = '' 185stmt->unknown = '13' 186done! 187