1--TEST-- 2Interface of the class mysqli_result 3--EXTENSIONS-- 4mysqli 5--SKIPIF-- 6<?php 7require_once('skipifconnectfailure.inc'); 8?> 9--FILE-- 10<?php 11 require('connect.inc'); 12 require('table.inc'); 13 14 $mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket); 15 $mysqli_result = $mysqli->query('SELECT * FROM test'); 16 $row = $mysqli_result->fetch_row(); 17 18 $link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket); 19 $res = mysqli_query($link, 'SELECT * FROM test'); 20 assert(mysqli_fetch_row($res) === $row); 21 22 printf("Parent class:\n"); 23 var_dump(get_parent_class($mysqli_result)); 24 25 printf("\nMethods:\n"); 26 $methods = get_class_methods($mysqli_result); 27 $expected_methods = array( 28 '__construct' => true, 29 'close' => true, 30 'data_seek' => true, 31 'fetch_all' => true, 32 'fetch_array' => true, 33 'fetch_assoc' => true, 34 'fetch_field' => true, 35 'fetch_field_direct' => true, 36 'fetch_fields' => true, 37 'fetch_object' => true, 38 'fetch_row' => true, 39 'fetch_column' => true, 40 'field_seek' => true, 41 'free' => true, 42 'free_result' => true, 43 'getIterator' => true, 44 ); 45 46 foreach ($methods as $k => $method) { 47 if (isset($expected_methods[$method])) { 48 unset($expected_methods[$method]); 49 unset($methods[$k]); 50 } 51 if ($method == 'mysqli_result') { 52 // get_class_method reports different constructor names 53 unset($expected_methods['__construct']); 54 unset($methods[$k]); 55 } 56 } 57 58 if (!empty($expected_methods)) { 59 printf("Dumping list of missing methods.\n"); 60 var_dump($expected_methods); 61 } 62 if (!empty($methods)) { 63 printf("Dumping list of unexpected methods.\n"); 64 var_dump($methods); 65 } 66 if (empty($expected_methods) && empty($methods)) 67 printf("ok\n"); 68 69 70 printf("\nClass variables:\n"); 71 $variables = array_keys(get_class_vars(get_class($mysqli_result))); 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($mysqli_result)); 78 foreach ($variables as $k => $var) 79 printf("%s\n", $var); 80 81 printf("\nMagic, magic properties:\n"); 82 83 assert(($tmp = mysqli_field_tell($res)) === $mysqli_result->current_field); 84 printf("mysqli_result->current_field = '%s'/%s ('%s'/%s)\n", 85 $mysqli_result->current_field, gettype($mysqli_result->current_field), 86 $tmp, gettype($tmp)); 87 88 assert(($tmp = mysqli_field_count($link)) === $mysqli_result->field_count); 89 printf("mysqli_result->field_count = '%s'/%s ('%s'/%s)\n", 90 $mysqli_result->field_count, gettype($mysqli_result->field_count), 91 $tmp, gettype($tmp)); 92 93 assert(($tmp = mysqli_fetch_lengths($res)) === $mysqli_result->lengths); 94 printf("mysqli_result->lengths -> '%s'/%s ('%s'/%s)\n", 95 ((is_array($mysqli_result->lengths)) ? implode(' ', $mysqli_result->lengths) : 'n/a'), 96 gettype($mysqli_result->lengths), 97 ((is_array($tmp)) ? implode(' ', $tmp) : 'n/a'), 98 gettype($tmp)); 99 100 assert(($tmp = mysqli_num_rows($res)) === $mysqli_result->num_rows); 101 printf("mysqli_result->num_rows = '%s'/%s ('%s'/%s)\n", 102 $mysqli_result->num_rows, gettype($mysqli_result->num_rows), 103 $tmp, gettype($tmp)); 104 105 assert(in_array($mysqli_result->type, array(MYSQLI_STORE_RESULT, MYSQLI_USE_RESULT))); 106 printf("mysqli_result->type = '%s'/%s\n", 107 ((MYSQLI_STORE_RESULT == $mysqli_result->type) ? 'store' : 'use'), 108 gettype($mysqli_result->type)); 109 110 printf("\nAccess to undefined properties:\n"); 111 printf("mysqli_result->unknown = '%s'\n", @$mysqli_result->unknown); 112 113 printf("\nConstructor:\n"); 114 if (!is_object($res = new mysqli_result($link))) 115 printf("[001] Expecting object/mysqli_result got %s/%s\n", gettye($res), $res); 116 117 try { 118 $res->num_rows; 119 } catch (Error $exception) { 120 echo $exception->getMessage() . "\n"; 121 } 122 123 if (!mysqli_query($link, "SELECT id FROM test ORDER BY id")) 124 printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 125 126 if (!is_object($res = new mysqli_result($link))) 127 printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 128 129 if (!is_object($res = new mysqli_result($link, MYSQLI_STORE_RESULT))) 130 printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 131 132 if (!is_object($res = new mysqli_result($link, MYSQLI_USE_RESULT))) 133 printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 134 135 $valid = array(MYSQLI_STORE_RESULT, MYSQLI_USE_RESULT); 136 do { 137 $mode = mt_rand(-1000, 1000); 138 } while (in_array($mode, $valid)); 139 140 if ($TEST_EXPERIMENTAL) { 141 ob_start(); 142 if (!is_object($res = new mysqli_result($link, $mode))) 143 printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 144 $content = ob_get_contents(); 145 ob_end_clean(); 146 if (!stristr($content, 'Invalid value for resultmode')) 147 printf("[009] Expecting warning because of invalid resultmode\n"); 148 } 149 150 print "done!"; 151?> 152--EXPECT-- 153Parent class: 154bool(false) 155 156Methods: 157ok 158 159Class variables: 160current_field 161field_count 162lengths 163num_rows 164type 165 166Object variables: 167 168Magic, magic properties: 169mysqli_result->current_field = '0'/integer ('0'/integer) 170mysqli_result->field_count = '2'/integer ('2'/integer) 171mysqli_result->lengths -> '1 1'/array ('1 1'/array) 172mysqli_result->num_rows = '6'/integer ('6'/integer) 173mysqli_result->type = 'store'/integer 174 175Access to undefined properties: 176mysqli_result->unknown = '' 177 178Constructor: 179mysqli_result object is already closed 180done! 181