mysql_fetch_object.phpt 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. --TEST--
  2. mysql_fetch_object()
  3. --SKIPIF--
  4. <?php
  5. require_once('skipif.inc');
  6. require_once('skipifconnectfailure.inc');
  7. ?>
  8. --FILE--
  9. <?php
  10. include "connect.inc";
  11. $tmp = NULL;
  12. $link = NULL;
  13. if (!is_null($tmp = @mysql_fetch_object()))
  14. printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  15. if (false !== ($tmp = @mysql_fetch_object($link)))
  16. printf("[002] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  17. require('table.inc');
  18. if (!$res = mysql_query("SELECT id AS ID, label FROM test AS TEST ORDER BY id LIMIT 5", $link)) {
  19. printf("[003] [%d] %s\n", mysql_errno($link), mysql_error($link));
  20. }
  21. var_dump(mysql_fetch_object($res));
  22. class mysql_fetch_object_test {
  23. public $a = null;
  24. public $b = null;
  25. public function toString() {
  26. var_dump($this);
  27. }
  28. }
  29. var_dump(mysql_fetch_object($res, 'mysql_fetch_object_test'));
  30. class mysql_fetch_object_construct extends mysql_fetch_object_test {
  31. public function __construct($a, $b) {
  32. $this->a = $a;
  33. $this->b = $b;
  34. }
  35. }
  36. var_dump(mysql_fetch_object($res, 'mysql_fetch_object_construct', null));
  37. var_dump(mysql_fetch_object($res, 'mysql_fetch_object_construct', array('a')));
  38. var_dump(mysql_fetch_object($res, 'mysql_fetch_object_construct', array('a', 'b')));
  39. var_dump(mysql_fetch_object($res, 'mysql_fetch_object_construct', array('a', 'b', 'c')));
  40. var_dump(mysql_fetch_object($res, 'mysql_fetch_object_construct', "no array and not null"));
  41. var_dump(mysql_fetch_object($res));
  42. var_dump(mysql_fetch_object($res, 'mysql_fetch_object_construct', array('a', 'b')));
  43. class mysql_fetch_object_private_construct {
  44. private function __construct($a, $b) {
  45. var_dump($a);
  46. }
  47. }
  48. var_dump(mysql_fetch_object($res, 'mysql_fetch_object_private_construct', array('a', 'b')));
  49. mysql_free_result($res);
  50. if (!$res = mysql_query("SELECT id AS ID, label FROM test AS TEST", $link)) {
  51. printf("[009] [%d] %s\n", mysql_errno($link), mysql_error($link));
  52. }
  53. mysql_free_result($res);
  54. var_dump(mysql_fetch_object($res));
  55. // Fatal error, script execution will end
  56. var_dump(mysql_fetch_object($res, 'this_class_does_not_exist'));
  57. mysql_close($link);
  58. print "done!";
  59. ?>
  60. --CLEAN--
  61. <?php
  62. require_once("clean_table.inc");
  63. ?>
  64. --EXPECTF--
  65. Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
  66. object(stdClass)#%d (2) {
  67. [%u|b%"ID"]=>
  68. %unicode|string%(1) "1"
  69. [%u|b%"label"]=>
  70. %unicode|string%(1) "a"
  71. }
  72. object(mysql_fetch_object_test)#%d (4) {
  73. [%u|b%"a"]=>
  74. NULL
  75. [%u|b%"b"]=>
  76. NULL
  77. [%u|b%"ID"]=>
  78. %unicode|string%(1) "2"
  79. [%u|b%"label"]=>
  80. %unicode|string%(1) "b"
  81. }
  82. Warning: Missing argument 1 for mysql_fetch_object_construct::__construct() in %s on line %d
  83. Warning: Missing argument 2 for mysql_fetch_object_construct::__construct() in %s on line %d
  84. Notice: Undefined variable: a in %s on line %d
  85. Notice: Undefined variable: b in %s on line %d
  86. object(mysql_fetch_object_construct)#%d (4) {
  87. [%u|b%"a"]=>
  88. NULL
  89. [%u|b%"b"]=>
  90. NULL
  91. [%u|b%"ID"]=>
  92. %unicode|string%(1) "3"
  93. [%u|b%"label"]=>
  94. %unicode|string%(1) "c"
  95. }
  96. Warning: Missing argument 2 for mysql_fetch_object_construct::__construct() in %s on line %d
  97. Notice: Undefined variable: b in %s on line %d
  98. object(mysql_fetch_object_construct)#%d (4) {
  99. [%u|b%"a"]=>
  100. %unicode|string%(1) "a"
  101. [%u|b%"b"]=>
  102. NULL
  103. [%u|b%"ID"]=>
  104. %unicode|string%(1) "4"
  105. [%u|b%"label"]=>
  106. %unicode|string%(1) "d"
  107. }
  108. object(mysql_fetch_object_construct)#%d (4) {
  109. [%u|b%"a"]=>
  110. %unicode|string%(1) "a"
  111. [%u|b%"b"]=>
  112. %unicode|string%(1) "b"
  113. [%u|b%"ID"]=>
  114. %unicode|string%(1) "5"
  115. [%u|b%"label"]=>
  116. %unicode|string%(1) "e"
  117. }
  118. bool(false)
  119. bool(false)
  120. bool(false)
  121. bool(false)
  122. bool(false)
  123. Warning: mysql_fetch_object(): %d is not a valid MySQL result resource in %s on line %d
  124. bool(false)
  125. Fatal error: Class 'this_class_does_not_exist' not found in %s on line %d