1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00
Files
archived-php-src/Zend/tests/asymmetric_visibility/__unset.phpt
Ilija Tovilo 8df557ac42 [RFC] Asymmetric visibility v2 (GH-15063)
Co-authored-by: Larry Garfield <larry@garfieldtech.com>
2024-08-27 02:04:48 +02:00

48 lines
740 B
PHP

--TEST--
Asymmetric visibility __unset
--FILE--
<?php
class Foo {
public private(set) string $bar;
public function setBar($bar) {
$this->bar = $bar;
}
public function unsetBar() {
unset($this->bar);
}
public function __unset($name) {
echo __METHOD__, "\n";
}
}
function test($foo) {
try {
unset($foo->bar);
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
}
$foo = new Foo();
test($foo);
$foo->unsetBar();
test($foo);
$foo->setBar('bar');
test($foo);
$foo->unsetBar();
test($foo);
?>
--EXPECT--
Cannot unset private(set) property Foo::$bar from global scope
Foo::__unset
Cannot unset private(set) property Foo::$bar from global scope
Foo::__unset