PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/bad/ext/mysqli/tests/mysqli_stmt_bind_result_references.php

http://github.com/facebook/hiphop-php
PHP | 238 lines | 189 code | 49 blank | 0 comment | 50 complexity | 5d757e0c621a19be86a0c3cea91b100f MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?php
  2. $test_table_name = 'test_mysqli_stmt_bind_result_references_table_1'; require('table.inc');
  3. $stmt = mysqli_stmt_init($link);
  4. if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test_mysqli_stmt_bind_result_references_table_1 ORDER BY id LIMIT 1"))
  5. printf("[001] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  6. if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test_mysqli_stmt_bind_result_references_table_1 ORDER BY id LIMIT 1"))
  7. printf("[001] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  8. print "plain vanilla...\n";
  9. unset($id); unset($label);
  10. $id = $label = null;
  11. if (true !== ($tmp = mysqli_stmt_bind_result($stmt, $id, $label)))
  12. printf("[002] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  13. if (!mysqli_stmt_execute($stmt) || !mysqli_stmt_fetch($stmt) || mysqli_stmt_fetch($stmt))
  14. printf("[003] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  15. var_dump($id);
  16. var_dump($label);
  17. print "reference, one level...\n";
  18. unset($id); unset($id_ref); unset($label); unset($label_ref);
  19. $id = null;
  20. $id_ref = &$id;
  21. $label = null;
  22. $label_ref = &$label;
  23. if (true !== ($tmp = mysqli_stmt_bind_result($stmt, $id_ref, $label_ref)))
  24. printf("[004] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  25. if (!mysqli_stmt_execute($stmt) || !mysqli_stmt_fetch($stmt) || mysqli_stmt_fetch($stmt))
  26. printf("[005] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  27. var_dump($id_ref);
  28. var_dump($id);
  29. var_dump($label_ref);
  30. var_dump($label);
  31. print "reference, two levels...\n";
  32. unset($id); unset($id_ref); unset($id_ref_ref); unset($label); unset($label_ref); unset($label_ref_ref);
  33. $id = null;
  34. $id_ref = &$id;
  35. $id_ref_ref = &$id_ref;
  36. $label = null;
  37. $label_ref = &$label;
  38. $label_ref_ref = &$label_ref;
  39. if (true !== ($tmp = mysqli_stmt_bind_result($stmt, $id_ref_ref, $label_ref_ref)))
  40. printf("[006] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  41. if (!mysqli_stmt_execute($stmt) || !mysqli_stmt_fetch($stmt) || mysqli_stmt_fetch($stmt))
  42. printf("[007] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  43. var_dump($id_ref_ref);
  44. var_dump($id_ref);
  45. var_dump($id);
  46. var_dump($label_ref_ref);
  47. var_dump($label_ref);
  48. var_dump($label);
  49. print "reference, \$GLOBALS...\n";
  50. unset($id); unset($id_ref); unset($label); unset($label_ref);
  51. $id = 100;
  52. $id_ref = &$GLOBALS['id'];
  53. $label = null;
  54. $label_ref = &$GLOBALS['label'];
  55. if (true !== ($tmp = mysqli_stmt_bind_result($stmt, $id_ref, $label_ref)))
  56. printf("[008] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  57. if (!mysqli_stmt_execute($stmt) || !mysqli_stmt_fetch($stmt) || mysqli_stmt_fetch($stmt))
  58. printf("[009] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  59. var_dump($id_ref);
  60. var_dump($id);
  61. var_dump($label_ref);
  62. var_dump($label);
  63. print "reference, same target...\n";
  64. $id = null;
  65. $label = &$id;
  66. if (true !== ($tmp = mysqli_stmt_bind_result($stmt, $id, $label)))
  67. printf("[010] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  68. if (!mysqli_stmt_execute($stmt) || !mysqli_stmt_fetch($stmt) || mysqli_stmt_fetch($stmt))
  69. printf("[011] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  70. var_dump($id);
  71. var_dump($label);
  72. print "reference, simple object...\n";
  73. unset($obj);
  74. $obj = new stdClass();
  75. $obj->id = null;
  76. $obj->label = null;
  77. if (true !== ($tmp = mysqli_stmt_bind_result($stmt, $obj->id, $obj->label)))
  78. printf("[012] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  79. if (!mysqli_stmt_execute($stmt) || !mysqli_stmt_fetch($stmt) || mysqli_stmt_fetch($stmt))
  80. printf("[013] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  81. var_dump($obj->id);
  82. var_dump($obj->label);
  83. print "reference, simple object w reference...\n";
  84. unset($id); unset($label); unset($obj);
  85. $obj = new stdClass();
  86. $obj->id = null;
  87. $obj->label = null;
  88. $id = &$obj->id;
  89. $label = &$obj->label;
  90. if (true !== ($tmp = mysqli_stmt_bind_result($stmt, $id, $label)))
  91. printf("[012] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  92. if (!mysqli_stmt_execute($stmt) || !mysqli_stmt_fetch($stmt) || mysqli_stmt_fetch($stmt))
  93. printf("[013] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  94. var_dump($obj->id);
  95. var_dump($obj->label);
  96. print "reference, simple object w reference, change after bind...\n";
  97. unset($id); unset($label); unset($obj);
  98. $obj = new stdClass();
  99. $obj->id = null;
  100. $obj->label = null;
  101. $id = &$obj->id;
  102. $label = &$obj->label;
  103. if (true !== ($tmp = mysqli_stmt_bind_result($stmt, $id, $label)))
  104. printf("[012] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  105. $label = &$obj->id;
  106. $id = null;
  107. if (!mysqli_stmt_execute($stmt) || !mysqli_stmt_fetch($stmt) || mysqli_stmt_fetch($stmt))
  108. printf("[013] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  109. var_dump($obj->id);
  110. var_dump($id);
  111. var_dump($obj->label);
  112. var_dump($label);
  113. print "reference, one level, change after bind...\n";
  114. unset($id); unset($label); unset($id_ref); unset($label_ref);
  115. $id = null;
  116. $id_ref = &$id;
  117. $label = null;
  118. $label_ref = &$label;
  119. if (true !== ($tmp = mysqli_stmt_bind_result($stmt, $id_ref, $label_ref)))
  120. printf("[014] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  121. $id_ref = 1;
  122. $label_ref = 1;
  123. if (!mysqli_stmt_execute($stmt) || !mysqli_stmt_fetch($stmt) || mysqli_stmt_fetch($stmt))
  124. printf("[015] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  125. var_dump($id_ref);
  126. var_dump($id);
  127. var_dump($label_ref);
  128. var_dump($label);
  129. print "reference, circle...\n";
  130. unset($id); unset($label_a); unset($label_b);
  131. $id = null;
  132. $label_a = &$label_b;
  133. $label_b = &$label_a;
  134. if (true !== ($tmp = mysqli_stmt_bind_result($stmt, $id, $label_a)))
  135. printf("[016] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  136. if (!mysqli_stmt_execute($stmt) || !mysqli_stmt_fetch($stmt) || mysqli_stmt_fetch($stmt))
  137. printf("[017] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  138. var_dump($id);
  139. var_dump($label_a);
  140. var_dump($label_b);
  141. print "reference, object, forward declaration...\n";
  142. unset($bar); unset($id); unset($label_ref);
  143. class foo {
  144. public $foo;
  145. public function foo() {
  146. $this->foo = &$this->bar;
  147. }
  148. }
  149. class bar extends foo {
  150. public $bar = null;
  151. }
  152. $bar = new bar();
  153. $id = null;
  154. $label_ref = &$bar->bar;
  155. if (true !== ($tmp = mysqli_stmt_bind_result($stmt, $id, $label_ref)))
  156. printf("[018] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  157. if (!mysqli_stmt_execute($stmt) || !mysqli_stmt_fetch($stmt) || mysqli_stmt_fetch($stmt))
  158. printf("[019] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  159. var_dump($id);
  160. var_dump($bar);
  161. var_dump($label_ref);
  162. print "references, object, private...\n";
  163. unset($bar); unset($id); unset($label);
  164. class mega_bar extends bar {
  165. private $id;
  166. public $id_ref;
  167. public function mega_bar() {
  168. $this->foo();
  169. $this->id_ref = &$this->id;
  170. }
  171. }
  172. $bar = new mega_bar();
  173. $id = &$bar->id_ref;
  174. $label = &$bar->foo;
  175. if (true !== ($tmp = mysqli_stmt_bind_result($stmt, $id, $label)))
  176. printf("[020] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  177. if (!mysqli_stmt_execute($stmt) || !mysqli_stmt_fetch($stmt) || mysqli_stmt_fetch($stmt))
  178. printf("[021] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  179. var_dump($id);
  180. var_dump($label);
  181. var_dump($bar);
  182. mysqli_stmt_close($stmt);
  183. mysqli_close($link);
  184. print "done!";
  185. ?>
  186. <?php error_reporting(0); ?>
  187. <?php
  188. $test_table_name = 'test_mysqli_stmt_bind_result_references_table_1'; require_once("clean_table.inc");
  189. ?>