[php-src] Issue #13039: if($var = fn() && !fn()) behavior
| From: | nextdebug | Date: | Wed, 27 Dec 2023 18:12:58 +0000 |
| Subject: | [php-src] Issue #13039: if($var = fn() && !fn()) behavior | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-246149@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/13039
Author: nextdebug
### Description
The following code:
```php
<?php
if ($user = $res->fetch() && !$user->deleted_at)
{ }
```
Resulted in this output:
```
$user == true
```
But I expected this output instead:
```
$user = $res->fetch()
```
The assign operator behavior within the if-statement is unsafe, because the sometimes assign the
object from $res->fetch, and another times assign the result of the logical test $res->fetch()
&& !$user->deleted_at
### PHP Version
PHP 8.x
### Operating System
Windows XAMPP