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

Reply via email to