RE: [PHP-DEV] Function proposal: varset

From: Date: Wed, 20 Apr 2011 16:00:14 +0000
Subject: RE: [PHP-DEV] Function proposal: varset
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-51958@lists.php.net to get a copy of this message
On Wed Apr 20 10:55 AM, Mark wrote: > > function varset($arr, $key, $default = '') { return (isset($arr[$key]) > ? $arr[$key] : $default); } > > where the call would be: > $var = varset($_GET, 'var'); > > I personally like both ways... > My proposal is to make this function a core php function in PHP 5.4. > The added benifit is obvious. People can, with this, use a way shorter > notation to validate if a given array element exists. Right now that > needs to be done with a ternary, filter_var or some other method > (there are quite a few ways to check for existence). > > I tried to look in the PHP source to see if i could make a patch to > add this but i couldn't find the function that defines the isset > function (i wanted to base it on that). So a pointer to the right > location would be nice (along with docs that tell me what i all need > to do to implement a new php function). https://svn.php.net/viewvc/php/php-src/trunk/Zend/zend_language_parser.y?rev ision=306938&view=markup Look for "isset_variables:", then zend_do_isset_or_isempty isset() lives in the parser and requires some advanced knowledge of the opcodes (personally I'm not there yet) > > So, what do you think of this? > I like the idea, it could also be called vardef() or var_default()

« previous php.internals (#51958) next »