Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79551 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 93710 invoked from network); 11 Dec 2014 00:13:02 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Dec 2014 00:13:02 -0000 Authentication-Results: pb1.pair.com header.from=cmbecker69@gmx.de; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=cmbecker69@gmx.de; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmx.de designates 212.227.17.21 as permitted sender) X-PHP-List-Original-Sender: cmbecker69@gmx.de X-Host-Fingerprint: 212.227.17.21 mout.gmx.net Received: from [212.227.17.21] ([212.227.17.21:52108] helo=mout.gmx.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E2/E0-19688-B81E8845 for ; Wed, 10 Dec 2014 19:13:00 -0500 Received: from [192.168.0.100] ([91.67.244.80]) by mail.gmx.com (mrgmx103) with ESMTPSA (Nemesis) id 0LmrZY-1XSr0q0HHw-00hAQ7; Thu, 11 Dec 2014 01:12:52 +0100 Message-ID: <5488E187.9010801@gmx.de> Date: Thu, 11 Dec 2014 01:12:55 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: Josh Watzman , Andrea Faulds CC: PHP internals References: <95A581EE-A062-4926-BE44-BCA87FC9B356@fb.com> <9230CB24-22FC-4A0E-A9D5-F02523B65A02@ajf.me> <583B9A4B-68FD-4FB1-B043-0D86E2480EAD@fb.com> In-Reply-To: <583B9A4B-68FD-4FB1-B043-0D86E2480EAD@fb.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:JR6+J+5MQonsE4ufsAcfw6lQC7LYPuiM5GEsi7wvFi4hYI5Gg2L iDUnrVJM46pp2BLZGLv7RC3rsbXSddK36mOgyrlKfpq04eYYnAV6eDf1CabsVQUCQpfAE0V hJ2hUTZTivAq2tJ6UWrcqIfCI4Ko0jWfS8IDBZpNDPYgvp1J8LSJVvFpvzcX88oaobneHxn LBL+YuoJtaEHTejuk4P3Q== X-UI-Out-Filterresults: notjunk:1; Subject: Re: [PHP-DEV] [RFC] Nullsafe calls From: cmbecker69@gmx.de (Christoph Becker) Josh Watzman wrote: > However, for a lot of failures, I don't feel that exceptions are > appropriate. I tend to only use them for exceptional behavior -- > usually, some failure that needs to be propagated up a few levels up > the stack, to an appropriate error boundary. This doesn't necessarily > mean a completely unrecoverable error, but it's *locally* > unrecoverable. For things that are completely recoverable, returning > null might be more appropriate and more lightweight, and then this > nullsafe operator would be useful at that point. FWIW, there is a third option: instead of returning null, return a null object[1]. That causes (slightly) more overhead, but it's quite flexible and works rather nicely without requiring the (IMO) ugly ?-> nor exception handling. Consider a non-existent user "foo": User::find('foo')?->getName() // returns null User::find('foo')->getName() // could also return '' or 'Unknown user' [1] -- Christoph M. Becker