1--TEST-- 2mysqli_fetch_object() 3--SKIPIF-- 4<?php 5require_once('skipif.inc'); 6require_once('skipifconnectfailure.inc'); 7?> 8--FILE-- 9<?php 10 require_once("connect.inc"); 11 set_error_handler('handle_catchable_fatal'); 12 13 $mysqli = new mysqli(); 14 try { 15 new mysqli_result($mysqli); 16 } catch (Error $exception) { 17 echo $exception->getMessage() . "\n"; 18 } 19 20 require('table.inc'); 21 if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) 22 printf("[002] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", 23 $host, $user, $db, $port, $socket); 24 25 if (!$res = $mysqli->query("SELECT id AS ID, label FROM test AS TEST ORDER BY id LIMIT 5")) { 26 printf("[003] [%d] %s\n", $mysqli->errno, $mysqli->error); 27 } 28 29 try { 30 if (!is_null($tmp = @$res->fetch_object($link, $link))) 31 printf("[005] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); 32 } catch (Error $e) { 33 handle_catchable_fatal($e->getCode(), $e->getMessage(), $e->getFile(), $e->getLine()); 34 } 35 36 37 try { 38 if (!is_null($tmp = @$res->fetch_object($link, $link, $link))) 39 printf("[006] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); 40 } catch (Error $e) { 41 handle_catchable_fatal($e->getCode(), $e->getMessage(), $e->getFile(), $e->getLine()); 42 } 43 44 $obj = mysqli_fetch_object($res); 45 if (($obj->ID !== "1") || ($obj->label !== "a") || (get_class($obj) != 'stdClass')) { 46 printf("[007] Object seems wrong. [%d] %s\n", $mysqli->errno, $mysqli->error); 47 var_dump($obj); 48 } 49 50 class mysqli_fetch_object_test { 51 52 public $a = null; 53 public $b = null; 54 55 public function toString() { 56 var_dump($this); 57 } 58 } 59 60 $obj = $res->fetch_object('mysqli_fetch_object_test'); 61 if (($obj->ID !== "2") || ($obj->label !== "b") || ($obj->a !== NULL) || ($obj->b !== NULL) || (get_class($obj) != 'mysqli_fetch_object_test')) { 62 printf("[008] Object seems wrong. [%d] %s\n", $mysqli->errno, $mysqli->error); 63 var_dump($obj); 64 } 65 66 class mysqli_fetch_object_construct extends mysqli_fetch_object_test { 67 68 public function __construct($a, $b) { 69 $this->a = $a; 70 $this->b = $b; 71 } 72 73 } 74 75 try { 76 $res->fetch_object('mysqli_fetch_object_construct', null); 77 } catch (TypeError $exception) { 78 echo $exception->getMessage() . "\n"; 79 mysqli_fetch_object($res); 80 } 81 82 try { 83 $obj = $res->fetch_object('mysqli_fetch_object_construct', array('a')); 84 if (($obj->ID !== "4") || ($obj->label !== "d") || ($obj->a !== 'a') || ($obj->b !== NULL) || (get_class($obj) != 'mysqli_fetch_object_construct')) { 85 printf("[010] Object seems wrong. [%d] %s\n", $mysqli->errno, $mysqli->error); 86 var_dump($obj); 87 } 88 } catch (Throwable $e) { 89 echo "Exception: " . $e->getMessage() . "\n"; 90 } 91 92 $obj = $res->fetch_object('mysqli_fetch_object_construct', array('a', 'b')); 93 if (($obj->ID !== "5") || ($obj->label !== "e") || ($obj->a !== 'a') || ($obj->b !== 'b') || (get_class($obj) != 'mysqli_fetch_object_construct')) { 94 printf("[011] Object seems wrong. [%d] %s\n", $mysqli->errno, $mysqli->error); 95 var_dump($obj); 96 } 97 98 var_dump($res->fetch_object('mysqli_fetch_object_construct', array('a', 'b', 'c'))); 99 var_dump(mysqli_fetch_object($res)); 100 101 mysqli_free_result($res); 102 103 if (!$res = mysqli_query($link, "SELECT id AS ID, label FROM test AS TEST")) { 104 printf("[012] [%d] %s\n", $mysqli->errno, $mysqli->error); 105 } 106 107 mysqli_free_result($res); 108 109 try { 110 mysqli_fetch_object($res); 111 } catch (Error $exception) { 112 echo $exception->getMessage() . "\n"; 113 } 114 115 try { 116 var_dump($res->fetch_object('this_class_does_not_exist')); 117 } catch (TypeError $exception) { 118 echo $exception->getMessage() . "\n"; 119 } 120 121 $mysqli->close(); 122 print "done!"; 123?> 124--CLEAN-- 125<?php 126 require_once("clean_table.inc"); 127?> 128--EXPECTF-- 129mysqli object is not fully initialized 130[0] Object of class mysqli could not be converted to string in %s on line %d 131[0] mysqli_result::fetch_object() expects at most 2 arguments, 3 given in %s on line %d 132mysqli_result::fetch_object(): Argument #2 ($constructor_args) must be of type array, null given 133Exception: Too few arguments to function mysqli_fetch_object_construct::__construct(), 1 passed and exactly 2 expected 134NULL 135NULL 136mysqli_result object is already closed 137mysqli_result::fetch_object(): Argument #1 ($class) must be a valid class name, this_class_does_not_exist given 138done! 139