2010-08-25 17:14:36 +08:00
|
|
|
--TEST--
|
|
|
|
Bug #52614 (Memory leak when writing on uninitialized variable returned from method call)
|
|
|
|
--FILE--
|
|
|
|
<?php
|
|
|
|
class foo {
|
2020-02-04 05:52:20 +08:00
|
|
|
public $a1;
|
|
|
|
public $a2 = array();
|
|
|
|
public $a3;
|
|
|
|
public $o1;
|
|
|
|
public $o2;
|
2018-09-17 01:16:42 +08:00
|
|
|
|
2020-02-04 05:52:20 +08:00
|
|
|
public function f1() {
|
|
|
|
return $this->a1;
|
|
|
|
}
|
2010-08-25 17:14:36 +08:00
|
|
|
|
2020-02-04 05:52:20 +08:00
|
|
|
public function f2() {
|
|
|
|
return $this->a2;
|
|
|
|
}
|
2010-08-25 17:14:36 +08:00
|
|
|
|
2020-02-04 05:52:20 +08:00
|
|
|
public function f3() {
|
|
|
|
$this->a3 = array();
|
|
|
|
return $this->a3;
|
|
|
|
}
|
2010-08-25 17:14:36 +08:00
|
|
|
|
2020-02-04 05:52:20 +08:00
|
|
|
public function f4() {
|
|
|
|
return $this->o1;
|
|
|
|
}
|
2010-08-25 17:14:36 +08:00
|
|
|
|
2020-02-04 05:52:20 +08:00
|
|
|
public function f5() {
|
|
|
|
$this->o2 = new stdClass;
|
|
|
|
return $this->o2;
|
|
|
|
}
|
2010-08-25 17:14:36 +08:00
|
|
|
|
2020-02-04 05:52:20 +08:00
|
|
|
public function &f6() {
|
|
|
|
return $this->a1;
|
|
|
|
}
|
2010-08-25 17:14:36 +08:00
|
|
|
|
2020-02-04 05:52:20 +08:00
|
|
|
public function f7(&$x) {
|
|
|
|
$x = 2;
|
|
|
|
}
|
2010-08-25 17:14:36 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$foo = new foo;
|
|
|
|
|
|
|
|
$foo->f1()[0] = 1;
|
|
|
|
var_dump($foo->a1);
|
|
|
|
|
|
|
|
$foo->f2()[0] = 1;
|
|
|
|
var_dump($foo->a2);
|
|
|
|
|
|
|
|
$foo->f3()[0] = 1;
|
|
|
|
var_dump($foo->a3);
|
|
|
|
|
2019-09-26 18:22:48 +08:00
|
|
|
try {
|
|
|
|
$foo->f4()->a = 1;
|
|
|
|
} catch (Error $e) {
|
|
|
|
echo $e->getMessage(), "\n";
|
|
|
|
}
|
2010-08-25 17:14:36 +08:00
|
|
|
var_dump($foo->o1);
|
|
|
|
|
|
|
|
$foo->f5()->a = 1;
|
|
|
|
var_dump($foo->o2);
|
|
|
|
|
|
|
|
$foo->a1[0] = 1;
|
|
|
|
$foo->f7($foo->f6()[0]);
|
|
|
|
var_dump($foo->a1[0]);
|
|
|
|
$foo->f1()[0]++;
|
|
|
|
var_dump($foo->a1[0]);
|
|
|
|
$foo->f6()[0]++;
|
|
|
|
var_dump($foo->a1[0]);
|
2020-08-09 17:06:57 +08:00
|
|
|
?>
|
2019-09-26 18:22:48 +08:00
|
|
|
--EXPECT--
|
2010-08-25 17:14:36 +08:00
|
|
|
NULL
|
|
|
|
array(0) {
|
|
|
|
}
|
|
|
|
array(0) {
|
|
|
|
}
|
2020-05-26 20:10:57 +08:00
|
|
|
Attempt to assign property "a" on null
|
2010-08-25 17:14:36 +08:00
|
|
|
NULL
|
2019-09-26 18:22:48 +08:00
|
|
|
object(stdClass)#3 (1) {
|
2010-08-25 17:14:36 +08:00
|
|
|
["a"]=>
|
|
|
|
int(1)
|
|
|
|
}
|
|
|
|
int(2)
|
|
|
|
int(2)
|
|
|
|
int(3)
|