php-src/Zend/tests/throwing_overloaded_compound_assign_op.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

46 lines
688 B
PHP

--TEST--
Exception in compound assign op should prevent call to overloaded object handlers
--FILE--
<?php
#[AllowDynamicProperties]
class Test {
public function __get($k) {
$this->$k = 42;
return 0;
}
}
$test = new ArrayObject;
$test[0] = 42;
try {
$test[0] %= 0;
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
var_dump($test);
$test2 = new Test;
try {
$test2->prop %= 0;
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
var_dump($test2);
?>
--EXPECT--
Modulo by zero
object(ArrayObject)#1 (1) {
["storage":"ArrayObject":private]=>
array(1) {
[0]=>
int(42)
}
}
Modulo by zero
object(Test)#3 (1) {
["prop"]=>
int(42)
}