Re: Seeking 'coalesce' php internal function
| From: | D. Dante Lorenso | Date: | Wed, 03 May 2006 06:05:41 +0000 |
| Subject: | Re: Seeking 'coalesce' php internal function | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-23102@lists.php.net to get a copy of this message | ||
D. Dante Lorenso wrote:
I don't think something like this can NOT be written in userspace because the 'isset' and 'empty' checks need to be run before arguments can be passed to a user function or warnings will start flying. A function like this simplifies code which used to look like this: if (!empty($_POST["postkey"])) {I mean "I DON'T think like this CAN be written in userspace". And, yes, there is a bug in that code up above (around $_GET testing), but the 'coalesce' function removes the test/set with identical values so removes those kinds of careless bugs. Dante$value = $_POST["postkey"];} elseif (!empty($_GET["getkey"])) {$value = $_POST["getkey"];} elseif (!empty($default_value)) {$value = $default_value;} else {$value = "hard coded value";} Into this: $value = coalesce($_POST["postkey"], $_GET["getkey"], $default_value, "hard coded value");