Req #77469 [Sus]: Support for multiple empty() arguments - like isset()

From: Date: Sun, 20 Jan 2019 12:51:35 +0000
Subject: Req #77469 [Sus]: Support for multiple empty() arguments - like isset()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-219093@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77469&edit=1 ID: 77469 User updated by: rich at milns dot com Reported by: rich at milns dot com Summary: Support for multiple empty() arguments - like isset() Status: Suspended Type: Feature/Change Request Package: Variables related Operating System: All PHP Version: 7.2.14 Block user comment: N Private report: N New Comment: Thanks for the update. I'm not quite sure I understand why empty() and isset() desugar differently? RE: isset() The manual says "If multiple parameters are supplied then isset() will return TRUE only if all of the parameters are set." For empty I would propose "If multiple parameters are supplied then empty() will return TRUE only if all of the parameters are not empty." That way, both behave in a similar way. To me, it would be most logical to assume that multiple isset() and multiple empty() would require all arguments to resolve to true in order to return true. If you only wanted to check that at least one of the multiple arguments provided to isset() or empty() are true then I would expect another function to be called instead, such as any_isset() or any_empty() for example. In my opinion empty() should return TRUE if all multiple arguments provided to the function are "empty". If you need to mix and match (e.g. "$x is empty OR $y is empty") then I would not expect to be able to pass multiple arguments to empty(). I agree that the RFC you linked to was incorrect, but do you think a new RFC along these lines would be acceptable? Previous Comments: ------------------------------------------------------------------------ [2019-01-18 11:23:38] nikic@php.net Ooops, I mixed up the logic ops. I meant that empty($a, $b) desugars to empty($a) || empty($b) and isset($a, $b) desugars to isset($a) && isset($b). ------------------------------------------------------------------------ [2019-01-18 11:22:19] nikic@php.net There has been an RFC for this feature, which was declined: https://wiki.php.net/rfc/variadic_empty The reason why this RFC failed is basically that empty($a, $b) must desugar to empty($a) && empty($b), while isset($a, $b) desugars to isset($a) || isset($b). Some people felt that this is confusing. I'm suspending this ticket, as a new RFC proposal would be necessary to accept this feature. ------------------------------------------------------------------------ [2019-01-16 14:37:11] rich at milns dot com Description: ------------ It would be useful if the empty() function also supported multiple function arguments, like isset() does. So basically "are all of these variables empty()". Similar to: Bug #12978: Multiple isset Test script: --------------- e.g. <?php // multiple variables supported by empty() var_dump(empty($var1, $var2, $var3)); // true ?> instead of: <?php // repeatedly calling empty() to check multiple variables $result = (empty($var1) and empty($var2) and empty($var3)); var_dump($result); // true ?> ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=77469&edit=1

« previous php.bugs (#219093) next »