On Wed, Apr 20, 2011 at 11:50 PM, Mark <mark...@gmail.com> wrote: > On Wednesday, April 20, 2011, D. Dante Lorenso <da...@lorenso.com> wrote: >> On 4/20/11 9:55 AM, Mark wrote: >> >> Hi, >> This proposal is for the often called line like this: >> $var = isset($_GET['var']) ? $_GET['var'] : ''; >> Only a shorter and imho a cleaner solution to get the same: >> $var = varset($_GET['var']); >> >> The implementation for this in PHP code is this: >> >> # Arg 1 = the variable to check for existence >> # Arg 2 = the default return value which is an empty string by default >> >> function varset($var, $default = '') >> { >> return (isset($var) ? $var : $default); >> } >> >> >> I proposed something similar over 5 years ago. It ain't gonna happen >> because PHP language can't support it. The Zend engine needs to be >> rewritten to remove the warnings and that's not something they are >> volunteering to do no matter how much people want it. >> >> http://markmail.org/message/yl26ebzcix35wtke >> >> My proposal was called "filled" since it was the opposite of "empty" which >> already existed. I extended the function to return the first non-empty >> value or null if all values evaluated as empty. >> >> You could use the function like this: >> >> $x = filled($_GET['x'], $obj->something, $default, 'default'); >> >> It would return the first argument where !empty($arg) evaluates as TRUE. >> >> There would need to be a companion function to check 'isset' opposite as you >> have proposed. >> >> Like I said, though, I don't think this can be done in the language because >> I think they ran out of OPCODES and would have to tear apart the whole PHP >> engine to support such a feature. >> >> -- Dante >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > Hi, > > well, i did propose 2 possible ways although the second one is a > little longer but still clean and readable. > And the second one is certainly possible to implement! > > Btw. i did look at the suggested core php code parts and even though i > can do nearly everything in php.. i have a hard time understanding how > the inner php parsing things actually work. There is no way i'm able > to make a patch for php. > > Regards, > Mark > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >
Hi, As Hannes said, the other thread discussing this feature (although the subject line may suggest otherwise) is still active, so please move this discussion there: "[PHP-DEV] Implicit isset/isempty check on short-ternary operator" Cheers, Arpad -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php