Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84128 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 78418 invoked from network); 1 Mar 2015 22:05:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Mar 2015 22:05:36 -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.192.178 as permitted sender) X-PHP-List-Original-Sender: smalyshev@gmail.com X-Host-Fingerprint: 209.85.192.178 mail-pd0-f178.google.com Received: from [209.85.192.178] ([209.85.192.178:41304] helo=mail-pd0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F1/01-06875-E2D83F45 for ; Sun, 01 Mar 2015 17:05:34 -0500 Received: by pdno5 with SMTP id o5so34548043pdn.8 for ; Sun, 01 Mar 2015 14:05:31 -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:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=dkiKqY14K0HHQ/GUjUxnChJpfl6rqV2r4/eIEJtG+3A=; b=vV8fhN6J6N0wZ2zs70LC/Xg2RnvJIKMwjgVoDLTyyPg53QcLqiLZPbVH3Zz2n2E+il C47Eht+c/Iui180xQPUHZR3t91K66uT6lorO+cS1agcdAXc5o1yD09631YMUzxvTmF0J sQQzo49ENnLvXDgi1ui8T4PST0sC9hap6Vo74SweGBbgFlK0VCmTctycywn+Y5SVvsnR GUWjVHmmWBx31Y3uQmXGRHu0Pb8T1o/iX12Lk5Vdic5D8FD/McmfA+vWZws5diGtYRql g9d6vGQQMYJV3Pjg77evqQVwwKCLHdQnl9opwcBTobdb8pZNYSK0tm9Hkq1YQ//HUeZL c9ew== X-Received: by 10.66.144.201 with SMTP id so9mr41963599pab.78.1425247531093; Sun, 01 Mar 2015 14:05:31 -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 qo4sm9913295pdb.71.2015.03.01.14.05.29 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 01 Mar 2015 14:05:30 -0800 (PST) Message-ID: <54F38D29.9080007@gmail.com> Date: Sun, 01 Mar 2015 14:05:29 -0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Dan Ackroyd , "internals@lists.php.net" References: In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC][DISCUSSION] Constructor behaviour of internal classes From: smalyshev@gmail.com (Stanislav Malyshev) Hi! > This email is to announce the formal opening of discussion for an RFC > to clean up the behaviour of the constructors shown by several > internal classes. > > https://wiki.php.net/rfc/internal_constructor_behaviour I'm not sure why this RFC assumes the exception is much better than returning null. Exceptions are harder to handle (requires separate syntax construct) and they are more expensive at runtime (must create an object, collect the backtrace, etc.). Also, not catching the exception immediately usually will lead to a complete application failure (usually with an obscure error message like "internal operation failed", since displaying raw exceptions to the user can be unsafe) instead of finer-grained handling. It is a long standing tradition in PHP that operations that can be expected to fail - like fopen(), date_create(), etc. - do not produce fatal errors but instead return error values which can be checked for and handled. It is true that some SPL classes departed from that, but this IMO was not an improvement but rather an annoyance that each time you use an SPL thing you have to write it in a try/catch block. That leads to much more boilerplate code than necessary. Now I understand that PHP model of doing things may be unusual for some people that come from other language background where everything throws exceptions for any slightest reason and there's no other means of error checking. But I think we can do better rather than that and have more flexible error handling - even if it would require people to be introduced to a concept they were not familiar with before coming to PHP, such as not using exceptions for everything. -- Stas Malyshev smalyshev@gmail.com