Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61695 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 31539 invoked from network); 24 Jul 2012 16:26:02 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Jul 2012 16:26:02 -0000 Authentication-Results: pb1.pair.com header.from=g.b.yahav@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=g.b.yahav@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.170 as permitted sender) X-PHP-List-Original-Sender: g.b.yahav@gmail.com X-Host-Fingerprint: 209.85.212.170 mail-wi0-f170.google.com Received: from [209.85.212.170] ([209.85.212.170:44001] helo=mail-wi0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 08/1E-17533-99CCE005 for ; Tue, 24 Jul 2012 12:26:02 -0400 Received: by wibhq12 with SMTP id hq12so3377125wib.5 for ; Tue, 24 Jul 2012 09:25:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:mime-version:content-type:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to:x-mailer; bh=JPufx3/1W6JsfaFd6tbkks1scShfY5a4FFuz4hCoZCs=; b=vQUj/fW9bjByHE7M/ZITqG+LNORxIo62mIXf3HbjiTHq6uBa8UtGvMbPyWm9JhlloA vsZAz9O7ioexIV8mNBs1Dnf7V4FohF5PD77Hqx4yDAiWUj2Nc5I+Q8FlIWZsPzyLiiiw r6P7ZVeMb/+Xgamc6L1meE6SUlsfhNG4EFhk0EptySZZJcc+C8wlYVEBEeB9YJiQMcfg wSLOnpFDwVaKvSMeOdhGz44yHE8whX+/Aq9elaBqBP88EsWK2vV4NMxiB/kcIltmVOgO xml6BY8gmxNWIjRt2dWw/XdOGV+18EFUq9Y1fYDzaGzhfagjVoBykoEDdfCW56jFGayN Z3lw== Received: by 10.180.83.106 with SMTP id p10mr8308266wiy.21.1343147159019; Tue, 24 Jul 2012 09:25:59 -0700 (PDT) Received: from [10.0.0.3] ([109.64.148.5]) by mx.google.com with ESMTPS id eu4sm5025734wib.2.2012.07.24.09.25.57 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 24 Jul 2012 09:25:58 -0700 (PDT) Mime-Version: 1.0 (Apple Message framework v1278) Content-Type: text/plain; charset=utf-8 In-Reply-To: Date: Tue, 24 Jul 2012 19:25:56 +0300 Cc: Galen Wright-Watson , internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: <4024424F-2D65-41EA-8E18-B2B8FCE94754@gmail.com> References: To: Alex Aulbach X-Mailer: Apple Mail (2.1278) Subject: Re: [PHP-DEV] Implicit isset in ternary operator From: g.b.yahav@gmail.com (Yahav Gindi Bar) On 24 =D7=91=D7=99=D7=95=D7=9C 2012, at 19:18, Alex Aulbach wrote: > 2012/7/24 Galen Wright-Watson : >>> Don't see much difference between >>>=20 >>> $a =3D $b ?: $c; >>>=20 >>> and (for example I used "i" for "if") >>>=20 >>> $a =3D _i($b, $c); >>=20 >>=20 >> When $b is defined, there isn't much appreciable difference. However, = this >> behavior already exists, so there isn't much to debate. In the cases = under >> discussion, a userland function can't suppress undefined variable & = index >> notices, so it isn't a viable substitution. >=20 > Hm, you're right. I normaly don't do such ugly things. :) >=20 > Hum. This behaviour is needed in very special contexts. In my eyes > only when printing out/filling up the templates etc. Under normal > circumstances I think, you should program without too much operators, > because a deflation of operators leads to - hm - deflation of the > language. Thats the same, as if everybody can create new words: after > a short time, nobody can understand anybody. >=20 > Hmmmm. But we can make this to a principle in this very, very closed = context. >=20 > So: What about if we can create new operators inside PHP with PHP? I > think not more than 36 operators are needed at any time in a project. > So we can do this: >=20 > set_operator_handler('i', function ($b, $c) { > if (empty($b)) return $b; > return $b; > }, OPERATOR_HANDLE_UNSET_WITHOUT_WARNINGS) >=20 > then we can do this: >=20 > $a =3D $a ?i: $b; >=20 > This should help for this case and could be a great things for those > very special cases, when you need the same operation over and over. >=20 > Comments > ---------------- >=20 > Context: I think those operators should be global. >=20 > Security: Hm. Could operators be overwritten? How to test, if an > operator already exists? I think it should work like including a file. > E. g. set_operator_handler_once() should be possible, so that a second > call isn't executed. >=20 > Other things: I don't like the first operator (the operator-name). Any > goof idea? >=20 >=20 > --=20 > Alex Aulbach >=20 > --=20 > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >=20 I don't think global operators is good idea since it can make a script = very complex and you'll have to learn many operators in case the one who = wrote it decided to make it "operator driven" However, if we're talking about operators, I do think that adding = operator override option (for the regular operators, such as +, -, * = etc.) will be great for OOP - but that's a different topic.