Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51985 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 27374 invoked from network); 23 Apr 2011 02:27:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Apr 2011 02:27:25 -0000 Authentication-Results: pb1.pair.com smtp.mail=mail_ben_schmidt@yahoo.com.au; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=mail_ben_schmidt@yahoo.com.au; sender-id=unknown; domainkeys=good Received-SPF: error (pb1.pair.com: domain yahoo.com.au from 98.138.91.39 cause and error) DomainKey-Status: good X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: mail_ben_schmidt@yahoo.com.au X-Host-Fingerprint: 98.138.91.39 nm2-vm0.bullet.mail.ne1.yahoo.com Received: from [98.138.91.39] ([98.138.91.39:43864] helo=nm2-vm0.bullet.mail.ne1.yahoo.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3F/32-02200-B0932BD4 for ; Fri, 22 Apr 2011 22:27:23 -0400 Received: from [98.138.90.55] by nm2.bullet.mail.ne1.yahoo.com with NNFMP; 23 Apr 2011 02:27:19 -0000 Received: from [98.138.87.11] by tm8.bullet.mail.ne1.yahoo.com with NNFMP; 23 Apr 2011 02:27:19 -0000 Received: from [127.0.0.1] by omp1011.mail.ne1.yahoo.com with NNFMP; 23 Apr 2011 02:27:19 -0000 X-Yahoo-Newman-Id: 732249.68125.bm@omp1011.mail.ne1.yahoo.com Received: (qmail 6558 invoked from network); 23 Apr 2011 02:27:19 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com.au; h=DKIM-Signature:Received:X-Yahoo-SMTP:X-YMail-OSG:X-Yahoo-Newman-Property:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:References:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=TXQo5AR/ruJ/W3IN2kZjwf+ga+uYYi2PImnGh1yXXsfuWPZMQygXWkzS+S36OXA2ie1xMunmxr/3dNx3DIHpM8CBFLQZo6U6StoLoqxBYmEjIJ7mMcwgZs4dPAXZJXvSMwAgs23RUCTtVPzT5T0cfN6zVwK9kUGEar+tsVp6OYE= ; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com.au; s=s1024; t=1303525639; bh=ppXzRlRcdLW0Fvb4T0XWnRDp8WeJUFtyJAm69dFR0Wo=; h=Received:X-Yahoo-SMTP:X-YMail-OSG:X-Yahoo-Newman-Property:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:References:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=SSGQQMWq/8dtGsjmkDjIl+oQIr715TcFeYKefUrBAbS4qHOyboe3X4AHTpvRBEXTZlJ4uvO38eS0tQpjCxN4EOhAj3JULeMLRvT6191Z+hc6/++yX+CSlrgp/mq57LLkQoWSKab00Bo1/GaRr2JmEO27LEmzIRrDpCwCQBxwmHw= Received: from thought.local (mail_ben_schmidt@124.148.147.145 with plain) by smtp143.mail.mud.yahoo.com with SMTP; 22 Apr 2011 19:27:18 -0700 PDT X-Yahoo-SMTP: enFMnPSswBAexaHyzgobwuUTrYOhZdJ0KRA2SjA- X-YMail-OSG: lwWFVNIVM1m8GFaqaKqMoU4jPROxx6D_Q1p2cVHuCWmaZDh yYVt2OzvddS_truwlBABY_kvnQ5x.vr08.ydetEtO2dy50PHWb0mcjI1l657 BtNbLHCaI8NALiKsDjG1OclGQr4COEAwmnDMtNxb3EI.Si8DQla_4wgz_qYw DWuZi0DUtOfxSVa0oJ92SFifoRzuARJTHz118_LWL8HjTIbUJ7AWg9.bifSA 4I66wxf3bWfY4lIaJAGdyIcDz8r6WH2IA4pS3e1k.ThYf.e9NDueKQrxBbKZ LGw_XAPB1H_CKY8tYtT1k8Fs2mcmlNUFxMNjtDNNSVEg2W8ipnYve2pLOLVa qcK4pO7GWwsUV2q1cvORDaiLEYq0- X-Yahoo-Newman-Property: ymail-3 Message-ID: <4DB23915.1040503@yahoo.com.au> Date: Sat, 23 Apr 2011 12:27:33 +1000 User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-GB; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 ThunderBrowse/3.3.5 MIME-Version: 1.0 To: Arpad Ray CC: Hannes Landeholm , internals@lists.php.net References: <4D9E96B6.6060401@lerdorf.com> <718216446.20110408143441@cypressintegrated.com> <4DA0E71C.9030008@gmail.com> <4DA63ED8.4080402@yahoo.com.au> <4DA6F2BC.10706@yahoo.com.au> <4DA6FB03.9040404@yahoo.com.au> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Implicit isset/isempty check on short-ternary operator From: mail_ben_schmidt@yahoo.com.au (Ben Schmidt) On 21/04/11 9:56 AM, Arpad Ray wrote: > I must say that the prospect of yet more new syntax is scary. It > really looks like Perl, and I wouldn't have the slightest clue what it > meant if I'd missed the release notes. I agree it looks a little bit strange. I think that's partly a benefit: it doesn't look like something so that you assume you know what it means but get it wrong; it drives you to the manual to find out what it means. > I've pined for something like coalesce($_GET['foo'], $defaults['foo'], > 42) for years, and I think that style is far more in keeping with the > PHP ethos, and far more readily understandable than this suggested new > syntax. As I see it, there a are a number of drawbacks to this approach. 1. It doesn't help with a bunch of common paradigms. For instance, $a['k'] = isset($a['k']) ? $a['k'] : "default" 2. I think it's too 'blunt'. For instance, if you write coalesce($_GET['foo'], $defaults['foo']) you probably actually do want to see a notice if $defaults['foo'] is not defined. But if you include 42 as a last resort default, you of course do not. Treating the last argument of a variable number of arguments differently is difficult and unintuitive, and even that would not always be desired anyway. Furthermore with something like $o->foo are you interested in whether $o is defined or not, or only in whether $o->foo is null? Particularly if you have many arguments, if you don't have tests that give full coverage of all the possibilities for each argument, notices very helpful for debugging could be easily undesirably silenced. 3. It can't be equivalent to isset() on every argument. isset() is very restricted in what it can operate on. For instance, isset(42) is not legal; nor is isset(some_function()); and so on. This kind of thing would be important to allow in coalescse(), but it would make things difficult to parse: to have any chance of making it work, you'd need to parse each item as if in isset(), and if it fails, backtrack and parse it as an expression, and then the coalesce() operation(s) (it could not be a function) would have to be able to deal with both scenarios for every argument. Nasty. 4. It's misleading regarding side effects because it looks like a function. If coalesce() were a function and you wrote coalesce($_GET['foo'],get_default('foo')), you would expect get_default() to be called before coalesce() and regardless of the state of $_GET['foo']. If it actually behaved like that, it would render coalesce() somewhat less useful, but it would be misleading if it didn't work like that. isset() gets away with this because it is restricted and only has one argument, but coalesce() wouldn't. To avoid/solve these problems: 1. Support missing paradigms: I suppose adding coalesce_set() and other constructs could conceptually provide for that. 2. Less blunt: You really need some kind of notice-free array index and/or variable lookup that can pinpoint the notice to be omitted. A function-like syntax doesn't really work: isset(), though better than coalesce(), is still too blunt for many use cases. It's also very verbose. Nobody wants to write coalesce(ifset($_GET['foo']),ifset($defaults['foo']),42) IMHO, it is better to have coalesce($_GET[?'foo'],$defaults[?'foo'],42) even though it's not 'familiar'. 3. Avoid isset()-like restrictions: You can use a !==null test that can be applied to any expression; if problem 1 is solved satisfactorily, an expression will simply be evaluated without generating a notice, and then compared to null. 4. Sensible side-effect behaviour: To get that, you really need an operator (or other language construct), and a function-like syntax is misleading. Although unfamiliar, $_GET[?'foo'] $: $defaults[?'foo'] $: 42 is less misleading. It also extends nicely to the assignment paradigm as $_GET[?'foo'] $:= $defaults[?'foo'] $: 42; Ben.