1
0
mirror of https://github.com/php/php-src.git synced 2026-03-30 04:02:19 +02:00
Files
archived-php-src/Zend/tests/bug52614.phpt
Nikita Popov a66c60cce3 Throw Error when writing property of non-object
This removes object auto-vivification support.

This also means that we can remove the corresponding special
handling for typed properites: We no longer need to check that a
property is convertible to stdClass if such a conversion might
take place indirectly due to a nested property write.

Additionally OBJ_W style operations now no longer modify the
object operand, and as such we no longer need to treat op1 as a
def in SSA form.

The next step would be to actually compile the whole LHS of OBJ_W
operations in R rather than W mode, but that causes issues with
SimpleXML, whose object handlers depend on the current compilation
structure.

Part of https://wiki.php.net/rfc/engine_warnings.
2019-09-27 10:11:47 +02:00

87 lines
1.1 KiB
PHP

--TEST--
Bug #52614 (Memory leak when writing on uninitialized variable returned from method call)
--FILE--
<?php
class foo {
public $a1;
public $a2 = array();
public $a3;
public $o1;
public $o2;
public function f1() {
return $this->a1;
}
public function f2() {
return $this->a2;
}
public function f3() {
$this->a3 = array();
return $this->a3;
}
public function f4() {
return $this->o1;
}
public function f5() {
$this->o2 = new stdClass;
return $this->o2;
}
public function &f6() {
return $this->a1;
}
public function f7(&$x) {
$x = 2;
}
}
$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);
try {
$foo->f4()->a = 1;
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
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]);
--EXPECT--
NULL
array(0) {
}
array(0) {
}
Attempt to assign property 'a' of non-object
NULL
object(stdClass)#3 (1) {
["a"]=>
int(1)
}
int(2)
int(2)
int(3)