Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84142 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 13184 invoked from network); 2 Mar 2015 04:11:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Mar 2015 04:11:01 -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.220.51 as permitted sender) X-PHP-List-Original-Sender: smalyshev@gmail.com X-Host-Fingerprint: 209.85.220.51 mail-pa0-f51.google.com Received: from [209.85.220.51] ([209.85.220.51:45240] helo=mail-pa0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CF/50-10542-4D2E3F45 for ; Sun, 01 Mar 2015 23:11:01 -0500 Received: by pablf10 with SMTP id lf10so40046750pab.12 for ; Sun, 01 Mar 2015 20:10:57 -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=9ALCLDMQBiS/hqIeXs5j5D7SisG/RpCxQwbM/VMzmvA=; b=R9iKWh67LviKfLmZvxqlWVkBQHBzF65t7g8oDoDzqSQtgkkc1cfrqyJn2Kw7Ox2KzV 3uMXcKaVgleCTYyqWAkHK5227JnQ6M60jgWmrPQgBBbhWt0KjIiGtlTjw0vXo3FAP/oR EjY+AlSbHsMxNm5Bug4kw0Ji9XiC7gMs5z1/LqI+nDaqYoMbDp4Eq7KLNZnM1WOKd8nm /z+T/wxSBTBeBoGM5qrCwB2FN0KzGCHOjRuMIQ6AxsJawP50B6CU3tLhhumAYrFfRfHO OZUlFkoGjza+gBY58tEFCeHh6HsNRoogZ3senLGkLosdruKqIEO7XlWSUWWcICrAX+ju nW5g== X-Received: by 10.68.235.74 with SMTP id uk10mr43730942pbc.33.1425269457264; Sun, 01 Mar 2015 20:10:57 -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 pk4sm10456466pbb.4.2015.03.01.20.10.55 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 01 Mar 2015 20:10:56 -0800 (PST) Message-ID: <54F3E2D0.9060203@gmail.com> Date: Sun, 01 Mar 2015 20:10:56 -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 CC: "internals@lists.php.net" References: <54F38D29.9080007@gmail.com> 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! > The difference is that fopen can fail even if passed parameters that > are correct e.g. due to file permission problems. Because of that the > failure is not exceptional and so needs to be checked. Having to do Failure of the formatter on wrong format or data is of the same kind - its not exceptional and only caused by input data that could be right but in this circumstance aren't. > When a user calls `new NumberFormatter()` they can know ahead of time > whether the parameters are valid or not. Any call with valid I certainly don't see how this can be true. The code can receive generated format and user-supplied locale (e.g. loaded from resource files and HTTP headers) and the developer can have no idea if it's correct or not. Exactly the same as with files or date_create(). > Because the programmer should only be passing in valid paramters any > failure is by it's nature an unexpected error. That's exactly like saying programmer should only try to open existing files so any failure by its nature is an unexpected error. You are trying to create a difference when there's none. But if you don't like fopen() there are many other factory functions that behave the same - like date_create() or simplexml_load_string(). You can claim that all these failures are somehow "not exceptional" and only date formatting using NumberFormatter is somehow "exceptional" but that doesn't sound very logical to me. > And to be precise, fopen does not return error values. It returns a > single error value of false. There is no indication of why the error > occurred. Exceptions allow a message to be attached saying what went > wrong, which is why they are preferred in a lot of cases. This is not relevant since error information can be retrieved by other methods, and intl has such facility (as do other APIs, most of the APIs have facilities to retrieve error information and very rarely they rely on exceptions for that - exceptions are not very good means of doing that). > You are one of the very few people who don't like exceptions. I Who said I don't like exceptions? I like exceptions, I adore, cherish and admire them - when they are used appropriately. What I am saying is not that exceptions are universally bad - but they are also not universally good, they should be used sparingly, in appropriate places, and not every situation where something is not going as planned should necessarily be an exception. > should be used only for exception circumstances. But the vast majority > of PHP programmers are completely used to them. They can not be used to them in the context of this RFC since PHP never had them in such context. They can be used to them in different contexts, but I've also seen a lot of boilerplate code and unclear error reporting growing from the fact that some code is too exception-happy. > Luckily, this RFC isn't a general discussion about error handling, it > is specifically about the behaviour of internal classes being > 'special' either by having behaviour which is not possible for > userland classes to do, or just being unusable after being > instantiated due to incorrect parameters. If something is unusable after being instantiated, it would better just let the user handle it instead of producing bad object. I agree with that - if you produce an object, it should be useful, otherwise no point in it. However, I disagree with the other part. -- Stas Malyshev smalyshev@gmail.com