[php-src] Issue #12531: When returning a property by reference that was previously deleted, it is recreated.
| From: | alexeyp0708 | Date: | Thu, 26 Oct 2023 20:19:43 +0000 |
| Subject: | [php-src] Issue #12531: When returning a property by reference that was previously deleted, it is recreated. | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-245657@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/12531
Author: alexeyp0708
### Description
The following code:
```php
<?php
class A{
public $prop='hello';
}
$a=new A;
unset($a->prop);
echo $a->prop;// Warning: Undefined property: A::$prop
var_dump(isset($a->prop),property_exists($a,'prop'));//false,true
$var= & $a->prop;
echo $a->prop;// empty (no errors)
var_dump(isset($a->prop),property_exists($a,'prop'));//false,true
```
Resulted in this output:
```
Warning: Undefined property: A::$prop in /home/user/scripts/code.php on line 12
bool(false)
bool(true)
bool(false)
bool(true)
```
But I expected this output instead:
```
Warning: Undefined property: A::$prop in /home/user/scripts/code.php on line 12
bool(false)
bool(true)
Warning: Undefined property: A::$prop in /home/user/scripts/code.php on line 12
bool(false)
bool(true)
```
The same is true when returning a property by reference in a method
```php
<?php
class A{
public $prop='hello';
public function getProp(){
return $this->prop;
}
public function & getRefProp(){
return $this->prop;
}
}
$a=new A;
unset($a->prop);
echo $a->getProp(); // Warning: Undefined property: A::$prop
echo $a->getRefProp(); // No error
echo $a->getProp(); // No error
```
Resulted in this output:
```
Warning: Undefined property: A::$prop in /home/user/scripts/code.php on line 5
```
But I expected this output instead:
```
Warning: Undefined property: A::$prop in /home/user/scripts/code.php on line 5
Warning: Undefined property: A::$prop in /home/user/scripts/code.php on line 5
Warning: Undefined property: A::$prop in /home/user/scripts/code.php on line 5
```
### PHP Version
PHP 8.3.0RC5, PHP 7.4.33
### Operating System
_No response_