Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51854 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 77030 invoked from network); 10 Apr 2011 14:04:12 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Apr 2011 14:04:12 -0000 Authentication-Results: pb1.pair.com header.from=rumi.kg@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=rumi.kg@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.42 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: rumi.kg@gmail.com X-Host-Fingerprint: 209.85.212.42 mail-vw0-f42.google.com Received: from [209.85.212.42] ([209.85.212.42:55307] helo=mail-vw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 00/72-55993-9D8B1AD4 for ; Sun, 10 Apr 2011 10:04:11 -0400 Received: by vwl1 with SMTP id 1so4001154vwl.29 for ; Sun, 10 Apr 2011 07:04:06 -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:content-type:content-transfer-encoding; bh=fEDcktqyfi0NmlUTS0n8wyq9TdhZ9lySPhb+aCfIeSE=; b=Cvk+h5a2f+zt8QMxYd6yP/fRTnrxzCUsUvk+tSx0k0v5SakiGfzyEyZHSN6WOM4RBo 1Tl5hA9Crzogy6A4MQyp5XPVjZIdcpZgvFgJzlMfFmk71gpL5bvIy1SQ//1QmDSC6SDu gqK2AS6BNg4OZc05ixFm0NT4sc6ICZCNSrv9Q= 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 :content-type:content-transfer-encoding; b=O5xfuLn06Prh1du2jH/rOzGVXwUzEpHCVyN+FJHTrdtLR3xH+VJXdRHWU0OTVsvaQq I/Ch/U2psl5K+3BOe0OwFM3Cc1oOsJEgFF4RzfcCnIPD63o9D6RAqo7ecxjOrrUFISR/ 520Y3d3pbnVUBgVGz5i5YlXQTPEjx0zbf3+Y4= MIME-Version: 1.0 Received: by 10.52.99.39 with SMTP id en7mr824343vdb.170.1302444246741; Sun, 10 Apr 2011 07:04:06 -0700 (PDT) Received: by 10.52.165.40 with HTTP; Sun, 10 Apr 2011 07:04:06 -0700 (PDT) In-Reply-To: <4DA0E71C.9030008@gmail.com> References: <4D950434.3060704@yahoo.com.au> <4D9E0543.1080600@lerdorf.com> <69.82.36433.EC33E9D4@pb1.pair.com> <4D9E34C4.5000406@lerdorf.com> <4D9E429B.20503@sugarcrm.com> <4D9E96B6.6060401@lerdorf.com> <718216446.20110408143441@cypressintegrated.com> <4DA0E71C.9030008@gmail.com> Date: Sun, 10 Apr 2011 16:04:06 +0200 Message-ID: To: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Implicit isset/isempty check on short-ternary operator From: rumi.kg@gmail.com (Rune Kaagaard) Hey again Updated here as always https://gist.github.com/909711. I've tried to write down the goal of this new feature. Which patterns do we want to make easier to write? Do you agree with the goals I've set? +1 From me of course :) Also added a proposal that would make userland implementations possible. ## Goal ## So what should be solved before this new feature can be considered a succes= ? The solution should offer DRY solutions to the following patterns: =A0 =A0// Set one variable from another or a default value. =A0 =A0// 1a. =A0 =A0$a =3D isset($b) ? $b : 'Default value'; =A0 =A0// 1b. =A0 =A0$a =3D !empty($b) ? $b : 'Default value'; =A0 =A0// Set one variable from itself or a default value. =A0 =A0// 2a. =A0 =A0$a =3D isset($a) ? $a : 'Default value'; =A0 =A0// 2b. =A0 =A0$a =3D !empty($a) ? $a : 'Default value'; =A0 =A0// Find the first set value from a range of variables and statements= . =A0 =A0// 3a. =A0 =A0$tmp =3D get_value(); =A0 =A0if (isset($tmp)) $a =3D $tmp; =A0 =A0$tmp =3D $myarr['mykey']; =A0 =A0if (!isset($a) && isset($tmp)) $a =3D $tmp; =A0 =A0if (!isset($a)) $a =3D 'Default value'; =A0 =A0// 3b. =A0 =A0$tmp =3D get_value(); =A0 =A0if (!empty($tmp)) $a =3D $tmp; =A0 =A0$tmp =3D $myarr['mykey']; =A0 =A0if (!isset($a) && !empty($tmp)) $a =3D $tmp; =A0 =A0if (!isset($a)) $a =3D 'Default value'; ## Proposal 2 : Making a userland implementation possible ## The one thing preventing us PHP end users for implementing our own solution= to this problem is - as discussed many times before - that it is not possible = to check if a passed argument can be referenced and then reference it. This proposal adds an `AS_REFERENCE` bitmask that can be passed as the second argument to `func_get_arg` which then in turn throws an `ArgNotReferencableException` if the argument is not referenceable. Below is an example of how `firstset` (ifsetor) could be implemented. =A0 =A0function firstset() { =A0 =A0 =A0 =A0$num_args =3D func_num_args(); =A0 =A0 =A0 =A0for ($i =3D 0; $i < $num_args; ++$i) { =A0 =A0 =A0 =A0 =A0 =A0try { =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0$arg =3D func_get_arg($i, AS_REFERENCE); =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (!isset($arg) { =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0$arg =3D null; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} =A0 =A0 =A0 =A0 =A0 =A0} catch (ArgNotReferencableException $e) { =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0$arg =3D func_get_arg($i); =A0 =A0 =A0 =A0 =A0 =A0} =A0 =A0 =A0 =A0 =A0 =A0if (isset($arg) { =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return $arg; =A0 =A0 =A0 =A0 =A0 =A0} =A0 =A0 =A0 =A0} =A0 =A0 =A0 =A0return null; =A0 =A0}