123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- --TEST--
- Exceptions thrown in operand cleaning must cause leak of return value
- --FILE--
- <?php
- try {
- var_dump(new class {
- function __toString() { return "a"; }
- function __destruct() { throw new Exception; }
- } . "foo");
- } catch (Exception $e) { print "caught Exception 1\n"; }
- try {
- var_dump([0] + [new class {
- function __destruct() { throw new Exception; }
- }]);
- } catch (Exception $e) { print "caught Exception 2\n"; }
- try {
- $foo = [0];
- var_dump($foo += [new class {
- function __destruct() { throw new Exception; }
- }]);
- } catch (Exception $e) { print "caught Exception 3\n"; }
- try {
- $foo = (object)["foo" => [0]];
- var_dump($foo->foo += [new class {
- function __destruct() { throw new Exception; }
- }]);
- } catch (Exception $e) { print "caught Exception 4\n"; }
- try {
- $foo = new class {
- function __get($x) { return [0]; }
- function __set($x, $y) {}
- };
- var_dump($foo->foo += [new class {
- function __destruct() { throw new Exception; }
- }]);
- } catch (Exception $e) { print "caught Exception 5\n"; }
- try {
- $foo = new class {
- public $bar = [0];
- function &__get($x) { return $this->bar; }
- };
- var_dump($foo->foo += [new class {
- function __destruct() { throw new Exception; }
- }]);
- } catch (Exception $e) { print "caught Exception 6\n"; }
- try {
- $foo = new class implements ArrayAccess {
- function offsetGet($x): mixed { return [0]; }
- function offsetSet($x, $y): void {}
- function offsetExists($x): bool { return true; }
- function offsetUnset($x): void {}
- };
- var_dump($foo[0] += [new class {
- function __destruct() { throw new Exception; }
- }]);
- } catch (Exception $e) { print "caught Exception 7\n"; }
- try {
- $foo = new class implements ArrayAccess {
- public $foo = [0];
- function &offsetGet($x): bool { return $this->foo; }
- function offsetSet($x, $y): void {}
- function offsetExists($x): bool { return true; }
- function offsetUnset($x): void {}
- };
- var_dump($foo[0] += [new class {
- function __destruct() { throw new Exception; }
- }]);
- } catch (Exception $e) { print "caught Exception 8\n"; }
- try {
- var_dump((function() { return new class {
- function __construct() { $this->foo = new stdClass; }
- function __destruct() { throw new Exception; }
- }; })()->foo++);
- } catch (Exception $e) { print "caught Exception 9\n"; }
- try {
- var_dump((function() { return new class {
- function __get($x) { return new stdClass; }
- function __set($x, $y) {}
- function __destruct() { throw new Exception; }
- }; })()->foo++);
- } catch (Exception $e) { print "caught Exception 10\n"; }
- try {
- var_dump((function() { return new class {
- function __construct() { $this->bar = new stdClass; }
- function &__get($x) { return $this->bar; }
- function __destruct() { throw new Exception; }
- }; })()->foo++);
- } catch (Exception $e) { print "caught Exception 11\n"; }
- try {
- var_dump(++(function() { return new class {
- function __construct() { $this->foo = new stdClass; }
- function __destruct() { throw new Exception; }
- }; })()->foo);
- } catch (Exception $e) { print "caught Exception 12\n"; }
- try {
- var_dump(++(function() { return new class {
- function __get($x) { return new stdClass; }
- function __set($x, $y) {}
- function __destruct() { throw new Exception; }
- }; })()->foo);
- } catch (Exception $e) { print "caught Exception 13\n"; }
- try {
- var_dump(++(function() { return new class {
- function __construct() { $this->bar = new stdClass; }
- function &__get($x) { return $this->bar; }
- function __destruct() { throw new Exception; }
- }; })()->foo);
- } catch (Exception $e) { print "caught Exception 14\n"; }
- try {
- var_dump((function() { return new class implements ArrayAccess {
- function offsetGet($x): mixed { return [new stdClass]; }
- function offsetSet($x, $y): void {}
- function offsetExists($x): bool { return true; }
- function offsetUnset($x): void {}
- function __destruct() { throw new Exception; }
- }; })()[0]++);
- } catch (Exception $e) { print "caught Exception 15\n"; }
- try {
- var_dump(++(function() { return new class implements ArrayAccess {
- function offsetGet($x): mixed { return [new stdClass]; }
- function offsetSet($x, $y): void {}
- function offsetExists($x): bool { return true; }
- function offsetUnset($x): void {}
- function __destruct() { throw new Exception; }
- }; })()[0]);
- } catch (Exception $e) { print "caught Exception 16\n"; }
- try {
- var_dump((new class {
- function __construct() { $this->foo = new stdClass; }
- function __destruct() { throw new Exception; }
- })->foo);
- } catch (Exception $e) { print "caught Exception 17\n"; }
- try {
- var_dump((new class {
- function __get($x) { return new stdClass; }
- function __set($x, $y) {}
- function __destruct() { throw new Exception; }
- })->foo);
- } catch (Exception $e) { print "caught Exception 18\n"; }
- try {
- var_dump((new class implements ArrayAccess {
- function offsetGet($x): mixed { return [new stdClass]; }
- function offsetSet($x, $y): void {}
- function offsetExists($x): bool { return true; }
- function offsetUnset($x): void {}
- function __destruct() { throw new Exception; }
- })[0]);
- } catch (Exception $e) { print "caught Exception 19\n"; }
- try {
- var_dump(isset((new class {
- function __construct() { $this->foo = new stdClass; }
- function __destruct() { throw new Exception; }
- })->foo->bar));
- } catch (Exception $e) { print "caught Exception 20\n"; }
- try {
- var_dump(isset((new class {
- function __get($x) { return new stdClass; }
- function __set($x, $y) {}
- function __destruct() { throw new Exception; }
- })->foo->bar));
- } catch (Exception $e) { print "caught Exception 21\n"; }
- try {
- var_dump(isset((new class implements ArrayAccess {
- function offsetGet($x): mixed { return [new stdClass]; }
- function offsetSet($x, $y): void {}
- function offsetExists($x): bool { return true; }
- function offsetUnset($x): void {}
- function __destruct() { throw new Exception; }
- })[0]->bar));
- } catch (Exception $e) { print "caught Exception 22\n"; }
- try {
- $foo = new class {
- function __destruct() { throw new Exception; }
- };
- var_dump($foo = new stdClass);
- } catch (Exception $e) { print "caught Exception 23\n"; }
- try {
- $foo = [new class {
- function __destruct() { throw new Exception; }
- }];
- var_dump($foo[0] = new stdClass);
- } catch (Exception $e) { print "caught Exception 24\n"; }
- try {
- $foo = (object) ["foo" => new class {
- function __destruct() { throw new Exception; }
- }];
- var_dump($foo->foo = new stdClass);
- } catch (Exception $e) { print "caught Exception 25\n"; }
- try {
- $foo = new class {
- function __get($x) {}
- function __set($x, $y) { throw new Exception; }
- };
- var_dump($foo->foo = new stdClass);
- } catch (Exception $e) { print "caught Exception 26\n"; }
- try {
- $foo = new class implements ArrayAccess {
- function offsetGet($x): mixed {}
- function offsetSet($x, $y): void { throw new Exception; }
- function offsetExists($x): bool { return true; }
- function offsetUnset($x): void {}
- };
- var_dump($foo[0] = new stdClass);
- } catch (Exception $e) { print "caught Exception 27\n"; }
- try {
- $foo = new class {
- function __destruct() { throw new Exception; }
- };
- $bar = new stdClass;
- var_dump($foo = &$bar);
- } catch (Exception $e) { print "caught Exception 28\n"; }
- try {
- $f = function() {
- return new class {
- function __toString() { return "a"; }
- function __destruct() { throw new Exception; }
- };
- };
- var_dump("{$f()}foo");
- } catch (Exception $e) { print "caught Exception 29\n"; }
- try {
- $f = function() {
- return new class {
- function __toString() { return "a"; }
- function __destruct() { throw new Exception; }
- };
- };
- var_dump("bar{$f()}foo");
- } catch (Exception $e) { print "caught Exception 30\n"; }
- try {
- var_dump((string) new class {
- function __toString() { $x = "Z"; return ++$x; }
- function __destruct() { throw new Exception; }
- });
- } catch (Exception $e) { print "caught Exception 31\n"; }
- try {
- var_dump(clone (new class {
- function __clone() { throw new Exception; }
- }));
- } catch (Exception $e) { print "caught Exception 32\n"; }
- ?>
- --EXPECTF--
- caught Exception 1
- caught Exception 2
- caught Exception 3
- caught Exception 4
- caught Exception 5
- caught Exception 6
- caught Exception 7
- caught Exception 8
- caught Exception 9
- caught Exception 10
- caught Exception 11
- caught Exception 12
- caught Exception 13
- caught Exception 14
- Notice: Indirect modification of overloaded element of ArrayAccess@anonymous has no effect in %s on line %d
- caught Exception 15
- Notice: Indirect modification of overloaded element of ArrayAccess@anonymous has no effect in %s on line %d
- caught Exception 16
- caught Exception 17
- caught Exception 18
- caught Exception 19
- caught Exception 20
- caught Exception 21
- caught Exception 22
- caught Exception 23
- caught Exception 24
- caught Exception 25
- caught Exception 26
- caught Exception 27
- caught Exception 28
- caught Exception 29
- caught Exception 30
- caught Exception 31
- caught Exception 32
|