Re: Seeking 'coalesce' php internal function

From: Date: Wed, 03 May 2006 06:16:01 +0000
Subject: Re: Seeking 'coalesce' php internal function
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-23104@lists.php.net to get a copy of this message
D. Please read the mailing list archives. And don't mention it again ;) - Steph ----- Original Message ----- From: "D. Dante Lorenso" <dante@vocalspace.com> To: <dante@lorenso.com> Cc: <internals@lists.php.net> Sent: Wednesday, May 03, 2006 8:05 AM Subject: Re: [PHP-DEV] Seeking 'coalesce' php internal function
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"])) {
       $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");
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 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php __________ NOD32 1.1380 (20060125) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com


« previous php.internals (#23104) next »