Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51967 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81300 invoked from network); 20 Apr 2011 23:39:41 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Apr 2011 23:39:41 -0000 Authentication-Results: pb1.pair.com smtp.mail=arraypad@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=arraypad@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.170 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: arraypad@gmail.com X-Host-Fingerprint: 209.85.220.170 mail-vx0-f170.google.com Received: from [209.85.220.170] ([209.85.220.170:35825] helo=mail-vx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A0/DF-24878-BBE6FAD4 for ; Wed, 20 Apr 2011 19:39:39 -0400 Received: by vxb40 with SMTP id 40so1013836vxb.29 for ; Wed, 20 Apr 2011 16:39:37 -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=5+1bzDmfbgMccSzb6fXVw7SqqyLZzvgYmm3PatoRdI4=; b=lBkL7rBCkc8n8AOHc/TgpaWEf0Dv2QkqmxkKdoIXUTnQBmZnKixfiFeG8TSmeD8eYX c2ebwPaw1ynNlgIR6dpJ80gi4AdZ3D/yU+myhDPbwBqlBRHWqEOfVoxgL0yHjNbwokKw TmzXJh7+oTyh3gy7T/AeZSfTwE8yG95km+bhE= 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=NcmWC63Ip17afbJTsSDeYaHQ3YyHW7S3riQz+pin+3DSSd/yO4CrdC3dR2qEtRaSvt kdwtoRnpGuAQe2Ap3COor23+ci58G7Fpu3pFWm+9kclak1a9rHMKEImzYV9vDm2QgpcB 9KCIdRrmPvwlcTHrwwGRQ+0dUIUIs/yXCXAWc= MIME-Version: 1.0 Received: by 10.52.67.105 with SMTP id m9mr5722033vdt.126.1303342776822; Wed, 20 Apr 2011 16:39:36 -0700 (PDT) Received: by 10.52.107.98 with HTTP; Wed, 20 Apr 2011 16:39:36 -0700 (PDT) In-Reply-To: References: <4DAF4500.7070207@lorenso.com> Date: Thu, 21 Apr 2011 00:39:36 +0100 Message-ID: To: Mark Cc: "dante@lorenso.com" , "internals@lists.php.net" Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Re: Function proposal: varset From: arraypad@gmail.com (Arpad Ray) On Wed, Apr 20, 2011 at 11:50 PM, Mark wrote: > 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 = because PHP language can't support it. =A0The Zend engine needs to be rewri= tten to remove the warnings and that's not something they are volunteering = to do no matter how much people want it. >> >> =A0=A0http://markmail.org/message/yl26ebzcix35wtke >> >> My proposal was called "filled" since it was the opposite of "empty" whi= ch already existed. =A0I extended the function to return the first non-empt= y value or null if all values evaluated as empty. >> >> You could use the function like this: >> >> =A0=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 beca= use 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 >> >> > 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 > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > Hi, As Hannes said, the other thread discussing this feature (although the subject line may suggest otherwise) is still active, so please move this discussion there: "[PHP-DEV] Implicit isset/isempty check on short-ternary operator" Cheers, Arpad