Re: New RFC : empty() function
| From: | Marcos Marcolin | Date: | Mon, 30 Oct 2023 15:03:50 +0000 |
| Subject: | Re: New RFC : empty() function | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-121524@lists.php.net to get a copy of this message | ||
Hello,
I understand that the idea of the RFC is about some behaviors of empty(), e.g.:
```php $var = ''; var_dump(empty($var)); // true $var= []; var_dump(empty($var)); // true $var= 0; var_dump(empty($var)); // true var_dump(empty($empty)); // true $var= true; var_dump(empty($var)); // false, $varis defined and has value $str = false; var_dump(empty($var)); // true, $varis defined and has value ```
According to the manual: “determine whether a variable is empty”.
However, according to my example, the variable is defined and has its value as 0 or false, and empty() returns true anyway. I confess that I've had some problems like this, and we chose not to use empty(), as sometimes 0 or false makes sense as a valid value.
Also, having is_empty() would be nice, but keeping it empty, otherwise there would be a huge break.
Maybe think of a strict empty() mode? Even so, it would change behavior.
Sorry if I didn't understand the discussion correctly.