Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51966 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 76197 invoked from network); 20 Apr 2011 22:50:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Apr 2011 22:50:50 -0000 Authentication-Results: pb1.pair.com header.from=markg85@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=markg85@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.170 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: markg85@gmail.com X-Host-Fingerprint: 209.85.216.170 mail-qy0-f170.google.com Received: from [209.85.216.170] ([209.85.216.170:48140] helo=mail-qy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5A/1F-24878-9436FAD4 for ; Wed, 20 Apr 2011 18:50:49 -0400 Received: by qyk32 with SMTP id 32so2653452qyk.8 for ; Wed, 20 Apr 2011 15:50:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=Q5sdmaN1OgugIR7uX7E+x3rfJGH9M4CYQeSPgD7CDjo=; b=MqOtllYqFpNrGfWNgcviLNRy5YkkqsPdngAoAxbCmrnP+GOXdL5h3qfGv5OYlfzxgH U9SXW5/K2ZJ1+2xeKg5owEx640Fbt9x0eT9rIV+DpJK1S3Z3Al2mFDxF3jrXX+grLwOi G+M6+uJI+PYRUmPM9xfRD+E4kiBcAhw95gbtE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=jeC5vZQBBiQ4cGmN5mINn4CxmZN0MKSXH2s0jkeSqRv0iS49afO55Xz+ZjQp5wBrvu pr6ALZrzquOaraY9tdl1Syz+gbC/MMbIgrzEbqSa3MA7lvLvybEO36wCVmeEWa1s/dxb MzmqoOOpA/n60bqlOqMikW5IAEouAvFojKN5w= MIME-Version: 1.0 Received: by 10.229.205.92 with SMTP id fp28mr5658360qcb.213.1303339846833; Wed, 20 Apr 2011 15:50:46 -0700 (PDT) Received: by 10.229.185.200 with HTTP; Wed, 20 Apr 2011 15:50:46 -0700 (PDT) In-Reply-To: <4DAF4500.7070207@lorenso.com> References: <4DAF4500.7070207@lorenso.com> Date: Thu, 21 Apr 2011 00:50:46 +0200 Message-ID: To: "dante@lorenso.com" Cc: "internals@lists.php.net" Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: Function proposal: varset From: markg85@gmail.com (Mark) On Wednesday, April 20, 2011, D. Dante Lorenso wrote: > On 4/20/11 9:55 AM, Mark wrote: > > Hi, > This proposal is for the often called line like this: > $var =3D isset($_GET['var']) ? $_GET['var'] : ''; > Only a shorter and imho a cleaner solution to get the same: > $var =3D varset($_GET['var']); > > The implementation for this in PHP code is this: > > # Arg 1 =3D the variable to check for existence > # Arg 2 =3D the default return value which is an empty string by default > > function varset($var, $default =3D '') > { > return (isset($var) ? $var : $default); > } > > > I proposed something similar over 5 years ago. =A0It ain't gonna happen b= ecause PHP language can't support it. =A0The Zend engine needs to be rewrit= ten to remove the warnings and that's not something they are volunteering t= o do no matter how much people want it. > > =A0http://markmail.org/message/yl26ebzcix35wtke > > My proposal was called "filled" since it was the opposite of "empty" whic= h already existed. =A0I 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: > > =A0$x =3D 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 becau= se I think they ran out of OPCODES and would have to tear apart the whole P= HP 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