[php-src] Issue #12695: Wrong magic methods sequence with `??` operator
| From: | nicolas-grekas | Date: | Thu, 16 Nov 2023 16:42:13 +0000 |
| Subject: | [php-src] Issue #12695: Wrong magic methods sequence with `??` operator | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-245819@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/12695
Author: nicolas-grekas
### Description
When
?? is used to check a property using magic methods, PHP unconditionnaly calls both
__isset and __get even when __isset did actually set the property.
Reproducer: https://3v4l.org/cDlNW
This script:
```php
#[AllowDynamicProperties]
class A
{
public function __get($n)
{
echo __FUNCTION__, "\n";
return $this->$n;
}
public function __isset($n)
{
echo __FUNCTION__, "\n";
$this->$n = 123;
return true;
}
}
$a = new A;
echo $a->foo ?? 234;
```
echoes this:
```
__isset
__get
123
```
while it should echo this:
```
__isset
123
```
### PHP Version
All since 7.0.6
### Operating System
_No response_