php-src/Zend/tests/bug30162.phpt
Nikita Popov 902d64390e Deprecate implicit dynamic properties
Writing to a proprety that hasn't been declared is deprecated,
unless the class uses the #[AllowDynamicProperties] attribute or
defines __get()/__set().

RFC: https://wiki.php.net/rfc/deprecate_dynamic_properties
2021-11-26 14:10:11 +01:00

55 lines
879 B
PHP

--TEST--
Bug #30162 (Catching exception in constructor couses lose of $this)
--FILE--
<?php
#[AllowDynamicProperties]
class FIIFO {
public function __construct() {
$this->x = "x";
throw new Exception;
}
}
#[AllowDynamicProperties]
class hariCow extends FIIFO {
public function __construct() {
try {
parent::__construct();
} catch(Exception $e) {
}
$this->y = "y";
try {
$this->z = new FIIFO;
} catch(Exception $e) {
}
}
public function __toString() {
return "Rusticus in asino sedet.";
}
}
try {
$db = new FIIFO();
} catch(Exception $e) {
}
var_dump($db);
$db = new hariCow;
var_dump($db);
?>
--EXPECTF--
Warning: Undefined variable $db in %s on line %d
NULL
object(hariCow)#%d (2) {
["x"]=>
string(1) "x"
["y"]=>
string(1) "y"
}