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

Reply via email to