Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79560 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 22905 invoked from network); 11 Dec 2014 07:35:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Dec 2014 07:35:26 -0000 Authentication-Results: pb1.pair.com smtp.mail=smalyshev@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=smalyshev@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.173 as permitted sender) X-PHP-List-Original-Sender: smalyshev@gmail.com X-Host-Fingerprint: 209.85.214.173 mail-ob0-f173.google.com Received: from [209.85.214.173] ([209.85.214.173:41305] helo=mail-ob0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 36/F2-05320-D3949845 for ; Thu, 11 Dec 2014 02:35:25 -0500 Received: by mail-ob0-f173.google.com with SMTP id uy5so1772828obc.4 for ; Wed, 10 Dec 2014 23:35:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=zjS1b6d9jYJvIJCzGTGbn3oxiUnBzICs0K4kfps2QbQ=; b=J8zt32FiV17Gsf9qud1bLozxU3wl0gyAd3TrB0bF/sHmZlTq9IOfnkEHMkf4uyUxlz eayr/0eTt6PO/4G7qeDPb2/Jj2KO1+w4hAphsXKPBOT4n1YA81cbiHim2QhOIbwS4PDC lh/IgoZUtti+1tZLUw4tzgnuduMYBgaHB/iFyZPY5ul4sot2H9yo5TEJReMt7kOmcFCL 7CWa8V/x5+0zVcSpxO+InYLuKMo1+WF3U4/dJ8xULCYV84tWxyY7eaCg92tipcG2ZtU2 4UT/s/qDkv1J1xHOcqpIjHPRJQKA6jzDvcMI9Y1YxF5YVJYfMhMcMIuZlH/5dL9WiwHv 0hAg== X-Received: by 10.202.90.213 with SMTP id o204mr5160526oib.62.1418283323352; Wed, 10 Dec 2014 23:35:23 -0800 (PST) Received: from Stas-Air.local (108-66-6-48.lightspeed.sntcca.sbcglobal.net. [108.66.6.48]) by mx.google.com with ESMTPSA id rh7sm171857oeb.0.2014.12.10.23.35.22 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Dec 2014 23:35:22 -0800 (PST) Message-ID: <54894936.9030003@gmail.com> Date: Wed, 10 Dec 2014 23:35:18 -0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: Andrea Faulds , Josh Watzman CC: PHP internals References: <95A581EE-A062-4926-BE44-BCA87FC9B356@fb.com> <9230CB24-22FC-4A0E-A9D5-F02523B65A02@ajf.me> In-Reply-To: <9230CB24-22FC-4A0E-A9D5-F02523B65A02@ajf.me> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [RFC] Nullsafe calls From: smalyshev@gmail.com (Stanislav Malyshev) Hi! > First, how is this substantially different from catching an > exception? With Nikita’s Exceptions in the Engine RFC > (https://wiki.php.net/rfc/engine_exceptions_for_php7), something like > this would be possible: > > try { return $foo->bar()->qux()->elePHPant()->dance(); } catch > (EngineException $e) { return NULL; } This actually is not a good code. Exceptions should not be used for something that is expected and normal, they should rather be used for situations where you code does something you could not predict. Programming for exceptions is usually bad style, and designing code flow expecting exceptions is usually bad idea. So I'd actually prefer being able, like, say, in Groovy, to say "try to call this long chain of whatever, but if it doesn't work out, just give me null". Of course, it is not for carefully controlled code with error reporting, but for some prototype code dealing with dirty data I found such shortcuts be rather helpful. I'd like PHP to be more Groovy and less Java, in other words ;) > Second, not short-circuiting is rather unintuitive. I think most > people would expect it to short-circuit. Note that ?? and isset() > short-circuit, so this would be inconsistent with existing > NULL-checking operators. So why, then, are you proposing that it > should not short-circuit? Is there some obscure case that this makes > easier? If anything, I’d expect that short-circuiting is the more > useful behaviour. For example, take the following hypothetical line > of code: > > $elePHPantParty->danceClub?->addToDanceFloor($elePHPantPool->remove()); I agree, for this feature I think it is a must that it would have no magic like evaluating code way past the first null in ?-> chain. As soon as there's null on the left of ?->, we should be done and return null, it should work just like the if would work. In fact, it can even compile to the same code as if() would. -- Stas Malyshev smalyshev@gmail.com