Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51958 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 29940 invoked from network); 20 Apr 2011 16:00:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Apr 2011 16:00:21 -0000 Authentication-Results: pb1.pair.com header.from=jbondc@openmv.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=jbondc@openmv.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain openmv.com from 64.15.152.204 cause and error) X-PHP-List-Original-Sender: jbondc@openmv.com X-Host-Fingerprint: 64.15.152.204 mail.ca.gdesolutions.com Received: from [64.15.152.204] ([64.15.152.204:50392] helo=mail.ca.gdesolutions.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 31/C7-24878-4130FAD4 for ; Wed, 20 Apr 2011 12:00:21 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.ca.gdesolutions.com (Postfix) with ESMTP id F3F485D12; Wed, 20 Apr 2011 12:00:15 -0400 (EDT) X-Virus-Scanned: amavisd-new at gdesolutions.com Received: from mail.ca.gdesolutions.com ([127.0.0.1]) by localhost (mail.ca.gdesolutions.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id EmSb3lTAF5Mp; Wed, 20 Apr 2011 12:00:15 -0400 (EDT) Received: from djbondc (modemcable005.23-57-74.mc.videotron.ca [74.57.23.5]) by mail.ca.gdesolutions.com (Postfix) with ESMTPSA id 2B2C45CFD; Wed, 20 Apr 2011 12:00:15 -0400 (EDT) To: "'Mark'" , References: In-Reply-To: Date: Wed, 20 Apr 2011 12:00:14 -0400 Message-ID: <002301cbff74$0994b160$1cbe1420$@com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: Acv/axNERYysaVf/Twe0yjHxl9T7bAABHLDQ Content-Language: en-ca Subject: RE: [PHP-DEV] Function proposal: varset From: jbondc@openmv.com ("Jonathan Bond-Caron") 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()