temporary_cleaning_013.phpt 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. --TEST--
  2. Exceptions thrown in operand cleaning must cause leak of return value
  3. --FILE--
  4. <?php
  5. try {
  6. var_dump(new class {
  7. function __toString() { return "a"; }
  8. function __destruct() { throw new Exception; }
  9. } . "foo");
  10. } catch (Exception $e) { print "caught Exception 1\n"; }
  11. try {
  12. var_dump([0] + [new class {
  13. function __destruct() { throw new Exception; }
  14. }]);
  15. } catch (Exception $e) { print "caught Exception 2\n"; }
  16. try {
  17. $foo = [0];
  18. var_dump($foo += [new class {
  19. function __destruct() { throw new Exception; }
  20. }]);
  21. } catch (Exception $e) { print "caught Exception 3\n"; }
  22. try {
  23. $foo = (object)["foo" => [0]];
  24. var_dump($foo->foo += [new class {
  25. function __destruct() { throw new Exception; }
  26. }]);
  27. } catch (Exception $e) { print "caught Exception 4\n"; }
  28. try {
  29. $foo = new class {
  30. function __get($x) { return [0]; }
  31. function __set($x, $y) {}
  32. };
  33. var_dump($foo->foo += [new class {
  34. function __destruct() { throw new Exception; }
  35. }]);
  36. } catch (Exception $e) { print "caught Exception 5\n"; }
  37. try {
  38. $foo = new class {
  39. public $bar = [0];
  40. function &__get($x) { return $this->bar; }
  41. };
  42. var_dump($foo->foo += [new class {
  43. function __destruct() { throw new Exception; }
  44. }]);
  45. } catch (Exception $e) { print "caught Exception 6\n"; }
  46. try {
  47. $foo = new class implements ArrayAccess {
  48. function offsetGet($x): mixed { return [0]; }
  49. function offsetSet($x, $y): void {}
  50. function offsetExists($x): bool { return true; }
  51. function offsetUnset($x): void {}
  52. };
  53. var_dump($foo[0] += [new class {
  54. function __destruct() { throw new Exception; }
  55. }]);
  56. } catch (Exception $e) { print "caught Exception 7\n"; }
  57. try {
  58. $foo = new class implements ArrayAccess {
  59. public $foo = [0];
  60. function &offsetGet($x): bool { return $this->foo; }
  61. function offsetSet($x, $y): void {}
  62. function offsetExists($x): bool { return true; }
  63. function offsetUnset($x): void {}
  64. };
  65. var_dump($foo[0] += [new class {
  66. function __destruct() { throw new Exception; }
  67. }]);
  68. } catch (Exception $e) { print "caught Exception 8\n"; }
  69. try {
  70. var_dump((function() { return new class {
  71. function __construct() { $this->foo = new stdClass; }
  72. function __destruct() { throw new Exception; }
  73. }; })()->foo++);
  74. } catch (Exception $e) { print "caught Exception 9\n"; }
  75. try {
  76. var_dump((function() { return new class {
  77. function __get($x) { return new stdClass; }
  78. function __set($x, $y) {}
  79. function __destruct() { throw new Exception; }
  80. }; })()->foo++);
  81. } catch (Exception $e) { print "caught Exception 10\n"; }
  82. try {
  83. var_dump((function() { return new class {
  84. function __construct() { $this->bar = new stdClass; }
  85. function &__get($x) { return $this->bar; }
  86. function __destruct() { throw new Exception; }
  87. }; })()->foo++);
  88. } catch (Exception $e) { print "caught Exception 11\n"; }
  89. try {
  90. var_dump(++(function() { return new class {
  91. function __construct() { $this->foo = new stdClass; }
  92. function __destruct() { throw new Exception; }
  93. }; })()->foo);
  94. } catch (Exception $e) { print "caught Exception 12\n"; }
  95. try {
  96. var_dump(++(function() { return new class {
  97. function __get($x) { return new stdClass; }
  98. function __set($x, $y) {}
  99. function __destruct() { throw new Exception; }
  100. }; })()->foo);
  101. } catch (Exception $e) { print "caught Exception 13\n"; }
  102. try {
  103. var_dump(++(function() { return new class {
  104. function __construct() { $this->bar = new stdClass; }
  105. function &__get($x) { return $this->bar; }
  106. function __destruct() { throw new Exception; }
  107. }; })()->foo);
  108. } catch (Exception $e) { print "caught Exception 14\n"; }
  109. try {
  110. var_dump((function() { return new class implements ArrayAccess {
  111. function offsetGet($x): mixed { return [new stdClass]; }
  112. function offsetSet($x, $y): void {}
  113. function offsetExists($x): bool { return true; }
  114. function offsetUnset($x): void {}
  115. function __destruct() { throw new Exception; }
  116. }; })()[0]++);
  117. } catch (Exception $e) { print "caught Exception 15\n"; }
  118. try {
  119. var_dump(++(function() { return new class implements ArrayAccess {
  120. function offsetGet($x): mixed { return [new stdClass]; }
  121. function offsetSet($x, $y): void {}
  122. function offsetExists($x): bool { return true; }
  123. function offsetUnset($x): void {}
  124. function __destruct() { throw new Exception; }
  125. }; })()[0]);
  126. } catch (Exception $e) { print "caught Exception 16\n"; }
  127. try {
  128. var_dump((new class {
  129. function __construct() { $this->foo = new stdClass; }
  130. function __destruct() { throw new Exception; }
  131. })->foo);
  132. } catch (Exception $e) { print "caught Exception 17\n"; }
  133. try {
  134. var_dump((new class {
  135. function __get($x) { return new stdClass; }
  136. function __set($x, $y) {}
  137. function __destruct() { throw new Exception; }
  138. })->foo);
  139. } catch (Exception $e) { print "caught Exception 18\n"; }
  140. try {
  141. var_dump((new class implements ArrayAccess {
  142. function offsetGet($x): mixed { return [new stdClass]; }
  143. function offsetSet($x, $y): void {}
  144. function offsetExists($x): bool { return true; }
  145. function offsetUnset($x): void {}
  146. function __destruct() { throw new Exception; }
  147. })[0]);
  148. } catch (Exception $e) { print "caught Exception 19\n"; }
  149. try {
  150. var_dump(isset((new class {
  151. function __construct() { $this->foo = new stdClass; }
  152. function __destruct() { throw new Exception; }
  153. })->foo->bar));
  154. } catch (Exception $e) { print "caught Exception 20\n"; }
  155. try {
  156. var_dump(isset((new class {
  157. function __get($x) { return new stdClass; }
  158. function __set($x, $y) {}
  159. function __destruct() { throw new Exception; }
  160. })->foo->bar));
  161. } catch (Exception $e) { print "caught Exception 21\n"; }
  162. try {
  163. var_dump(isset((new class implements ArrayAccess {
  164. function offsetGet($x): mixed { return [new stdClass]; }
  165. function offsetSet($x, $y): void {}
  166. function offsetExists($x): bool { return true; }
  167. function offsetUnset($x): void {}
  168. function __destruct() { throw new Exception; }
  169. })[0]->bar));
  170. } catch (Exception $e) { print "caught Exception 22\n"; }
  171. try {
  172. $foo = new class {
  173. function __destruct() { throw new Exception; }
  174. };
  175. var_dump($foo = new stdClass);
  176. } catch (Exception $e) { print "caught Exception 23\n"; }
  177. try {
  178. $foo = [new class {
  179. function __destruct() { throw new Exception; }
  180. }];
  181. var_dump($foo[0] = new stdClass);
  182. } catch (Exception $e) { print "caught Exception 24\n"; }
  183. try {
  184. $foo = (object) ["foo" => new class {
  185. function __destruct() { throw new Exception; }
  186. }];
  187. var_dump($foo->foo = new stdClass);
  188. } catch (Exception $e) { print "caught Exception 25\n"; }
  189. try {
  190. $foo = new class {
  191. function __get($x) {}
  192. function __set($x, $y) { throw new Exception; }
  193. };
  194. var_dump($foo->foo = new stdClass);
  195. } catch (Exception $e) { print "caught Exception 26\n"; }
  196. try {
  197. $foo = new class implements ArrayAccess {
  198. function offsetGet($x): mixed {}
  199. function offsetSet($x, $y): void { throw new Exception; }
  200. function offsetExists($x): bool { return true; }
  201. function offsetUnset($x): void {}
  202. };
  203. var_dump($foo[0] = new stdClass);
  204. } catch (Exception $e) { print "caught Exception 27\n"; }
  205. try {
  206. $foo = new class {
  207. function __destruct() { throw new Exception; }
  208. };
  209. $bar = new stdClass;
  210. var_dump($foo = &$bar);
  211. } catch (Exception $e) { print "caught Exception 28\n"; }
  212. try {
  213. $f = function() {
  214. return new class {
  215. function __toString() { return "a"; }
  216. function __destruct() { throw new Exception; }
  217. };
  218. };
  219. var_dump("{$f()}foo");
  220. } catch (Exception $e) { print "caught Exception 29\n"; }
  221. try {
  222. $f = function() {
  223. return new class {
  224. function __toString() { return "a"; }
  225. function __destruct() { throw new Exception; }
  226. };
  227. };
  228. var_dump("bar{$f()}foo");
  229. } catch (Exception $e) { print "caught Exception 30\n"; }
  230. try {
  231. var_dump((string) new class {
  232. function __toString() { $x = "Z"; return ++$x; }
  233. function __destruct() { throw new Exception; }
  234. });
  235. } catch (Exception $e) { print "caught Exception 31\n"; }
  236. try {
  237. var_dump(clone (new class {
  238. function __clone() { throw new Exception; }
  239. }));
  240. } catch (Exception $e) { print "caught Exception 32\n"; }
  241. ?>
  242. --EXPECTF--
  243. caught Exception 1
  244. caught Exception 2
  245. caught Exception 3
  246. caught Exception 4
  247. caught Exception 5
  248. caught Exception 6
  249. caught Exception 7
  250. caught Exception 8
  251. caught Exception 9
  252. caught Exception 10
  253. caught Exception 11
  254. caught Exception 12
  255. caught Exception 13
  256. caught Exception 14
  257. Notice: Indirect modification of overloaded element of ArrayAccess@anonymous has no effect in %s on line %d
  258. caught Exception 15
  259. Notice: Indirect modification of overloaded element of ArrayAccess@anonymous has no effect in %s on line %d
  260. caught Exception 16
  261. caught Exception 17
  262. caught Exception 18
  263. caught Exception 19
  264. caught Exception 20
  265. caught Exception 21
  266. caught Exception 22
  267. caught Exception 23
  268. caught Exception 24
  269. caught Exception 25
  270. caught Exception 26
  271. caught Exception 27
  272. caught Exception 28
  273. caught Exception 29
  274. caught Exception 30
  275. caught Exception 31
  276. caught Exception 32