[php-src] Issue #15644: Property hooks + asymmetric visibility don't work together
| From: | martinkobelka | Date: | Thu, 29 Aug 2024 21:40:35 +0000 |
| Subject: | [php-src] Issue #15644: Property hooks + asymmetric visibility don't work together | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-247634@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/15644
Author: martinkobelka
### Description
The following code:
```php
<?php
class PhoneClass
{
public private(set) string $phone {
set {
$this->phone = $value;
}
get {
return $this->phone;
}
}
}
$foo = new PrefixStyle();
$foo->phone = "123 456 789";
var_dump($foo->phone);
```
Resulted in this output:
```
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
```
But I expected this output instead:
```
string(11) "123 456 789"
```
Set is not private
When I try it without property hooks, it works fine. Code below works fine and throw error.
```php
<?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