-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Closed
Description
Description
The following code:
<?php
class PhoneClass
{
public private(set) string $phone {
set {
$this->phone = $value;
}
get {
return $this->phone;
}
}
}
$foo = new PhoneClass();
$foo->phone = "123 456 789";
var_dump($foo->phone);
Resulted in this output:
string(11) "123 456 789"
But I expected this output instead:
Fatal error: Uncaught Error: Cannot modify private(set) property PhoneClass::$phone from global scope in /php-test/index.php:9 Stack trace: #0 {main} thrown in /php-test/index.php on line 15
Set is not private
When I try it without property hooks, it works fine. Code below works fine and throw error.
<?php
class PhoneClass
{
private(set) string $phone;
}
$foo = new PhoneClass();
$foo->phone = "123 456 789";
var_dump($foo->phone);
PHP Version
PHP 8.4.0Beta
Operating System
Ubuntu 20