Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84134 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 90281 invoked from network); 1 Mar 2015 23:32:14 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Mar 2015 23:32:14 -0000 Authentication-Results: pb1.pair.com smtp.mail=danack@basereality.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=danack@basereality.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain basereality.com from 209.85.160.180 cause and error) X-PHP-List-Original-Sender: danack@basereality.com X-Host-Fingerprint: 209.85.160.180 mail-yk0-f180.google.com Received: from [209.85.160.180] ([209.85.160.180:44719] helo=mail-yk0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 94/31-17251-D71A3F45 for ; Sun, 01 Mar 2015 18:32:13 -0500 Received: by ykp131 with SMTP id 131so11849226ykp.11 for ; Sun, 01 Mar 2015 15:32:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=jrSuYxzVvCRORA/ZjVzGL8Rjl29ytHfJrbMb4BZdBow=; b=NFKGJ/Dblg+xxsDU9jJqo0CC2vgF9pFlyOtmmsAPBCHadwF0GDjhFivOjHGa8fo9M1 vzsWyEQnU6kFRnb5CY/E/lOfJmsEMcTN6CXfUjhpHGYL5FC71ch9JlF/TYSlCZLfvZ4F mXhLf4rG6kNaIhMpAwNuc+lh0jW0AQn7GBXxJk6ePKcQHR2fM29mSNjCJw6UyWUeugAj KmxEEuUn0CAokQCwQSdJ6v5rpO2vfC/2ZlePaja0xpuRZeo+psK81i2o6WSGpFfzS8ve uIAt/zzqarHeFulbQqokfxg2BOxLMrddyqLmrJbI05agnoeX/d4dyIOG4KjKmUO0L4RM 4yUQ== X-Gm-Message-State: ALoCoQlek68FuV4FciEE9A37G4x/8iik12XZbdVPqLm3B/zozdwlPardUcj65skHMIvQwx0o1QBq MIME-Version: 1.0 X-Received: by 10.170.100.87 with SMTP id r84mr25110137yka.73.1425252729868; Sun, 01 Mar 2015 15:32:09 -0800 (PST) Received: by 10.170.71.86 with HTTP; Sun, 1 Mar 2015 15:32:09 -0800 (PST) X-Originating-IP: [78.147.3.129] In-Reply-To: <54F38D29.9080007@gmail.com> References: <54F38D29.9080007@gmail.com> Date: Sun, 1 Mar 2015 23:32:09 +0000 Message-ID: To: Stanislav Malyshev Cc: "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [RFC][DISCUSSION] Constructor behaviour of internal classes From: danack@basereality.com (Dan Ackroyd) On 1 March 2015 at 22:05, Stanislav Malyshev wrote: > I'm not sure why this RFC assumes the exception is much better than > returning null. > > It is a long standing tradition in PHP that operations that can be > expected to fail - like fopen().. do not produce > fatal errors but instead return error values which can be checked for > and handled. 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 this through exceptions would be annoying which is why people prefer to use procedural function for handling files, even when OO style interfaces are available. When a user calls `new NumberFormatter()` they can know ahead of time whether the parameters are valid or not. Any call with valid parameters will succeed. Calls with invalid parameters will fail. Because the programmer should only be passing in valid paramters any failure is by it's nature an unexpected error. 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. > 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. You are one of the very few people who don't like exceptions. I completely agree exceptions shouldn't be used everywhere and that they should be used only for exception circumstances. But the vast majority of PHP programmers are completely used to them. If you don't see the benefits of using exceptions in some cases by now, it's very unlikely that any argument is going to persuade you of how they can be used (judiciously) to write clean code. 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. cheers Dan