Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51965 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 65861 invoked from network); 20 Apr 2011 20:41:43 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Apr 2011 20:41:43 -0000 Authentication-Results: pb1.pair.com smtp.mail=dante@lorenso.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=dante@lorenso.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lorenso.com from 74.125.83.42 cause and error) X-PHP-List-Original-Sender: dante@lorenso.com X-Host-Fingerprint: 74.125.83.42 mail-gw0-f42.google.com Received: from [74.125.83.42] ([74.125.83.42:50330] helo=mail-gw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 28/DD-24878-5054FAD4 for ; Wed, 20 Apr 2011 16:41:42 -0400 Received: by gwb17 with SMTP id 17so370303gwb.29 for ; Wed, 20 Apr 2011 13:41:39 -0700 (PDT) Received: by 10.236.72.199 with SMTP id t47mr6379671yhd.313.1303332099265; Wed, 20 Apr 2011 13:41:39 -0700 (PDT) Received: from Dante-Lorensos-MacBook-Pro.local (99-147-138-4.lightspeed.allntx.sbcglobal.net [99.147.138.4]) by mx.google.com with ESMTPS id p42sm581564yhm.82.2011.04.20.13.41.37 (version=SSLv3 cipher=OTHER); Wed, 20 Apr 2011 13:41:38 -0700 (PDT) Message-ID: <4DAF4500.7070207@lorenso.com> Date: Wed, 20 Apr 2011 15:41:36 -0500 Reply-To: dante@lorenso.com User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.15) Gecko/20110303 Lightning/1.0b2 Thunderbird/3.1.9 MIME-Version: 1.0 To: internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Function proposal: varset From: dante@lorenso.com ("D. Dante Lorenso") 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