Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80776 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 84727 invoked from network); 19 Jan 2015 07:49:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Jan 2015 07:49:06 -0000 Authentication-Results: pb1.pair.com header.from=petercowburn@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=petercowburn@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.44 as permitted sender) X-PHP-List-Original-Sender: petercowburn@gmail.com X-Host-Fingerprint: 74.125.82.44 mail-wg0-f44.google.com Received: from [74.125.82.44] ([74.125.82.44:41874] helo=mail-wg0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 22/83-64889-1F6BCB45 for ; Mon, 19 Jan 2015 02:49:05 -0500 Received: by mail-wg0-f44.google.com with SMTP id y19so30158860wgg.3 for ; Sun, 18 Jan 2015 23:49:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=rLxttGAoVwwUPUD40Tp5t6Ht2C96x1XdoYn2/Wm64/4=; b=l0howXIeukWOvwWXQDBNKhclWBe1zOoIYprQo3ON2vdsajBzcj++TIXqfZE6Cg2qGc dJO1qA5fBuaa91vW2F2xPqPfMYga3Hkofpuony+P+ITr5UcKdvqguuOSVYVg/vmwetks ASsvQskZgCHCpcrv6XIlsQTngiOclvdekdZ85CNaOf6mv05Li4scP5sXyngkB++g/3ye Nw1nCVz3ZX2rdgRYV2ZzP9KbRz2ioIWa1QbHSTxgAojp7uLwKzQeNMijxb22EJB/3Y+O d2aUxglkjD0p0UFhxTmyDgisOXIcBq9ZaEEWRhm2fPYkclIgLERNBmG+bIwQ0vVmw96a CuGg== X-Received: by 10.194.190.162 with SMTP id gr2mr48249476wjc.13.1421653742156; Sun, 18 Jan 2015 23:49:02 -0800 (PST) MIME-Version: 1.0 Received: by 10.27.100.8 with HTTP; Sun, 18 Jan 2015 23:48:21 -0800 (PST) In-Reply-To: <54BC9A97.9020103@gmail.com> References: <003201d0326b$6fd27f60$4f777e20$@tekwire.net> <54BC9A97.9020103@gmail.com> Date: Mon, 19 Jan 2015 07:48:21 +0000 Message-ID: To: Stanislav Malyshev Cc: Marco Pivetta , francois@tekwire.net, Dan Ackroyd , PHP Internals List Content-Type: multipart/alternative; boundary=047d7b6249984b8399050cfc8e79 Subject: Re: [PHP-DEV] Class constructor behaviour From: petercowburn@gmail.com (Peter Cowburn) --047d7b6249984b8399050cfc8e79 Content-Type: text/plain; charset=UTF-8 On 19 January 2015 at 05:48, Stanislav Malyshev wrote: > Hi! > > > A constructor that fails is a hard failure (factory method failed to > > produce the expected value), and is an exceptional case that can or > cannot > > be handled (via catch). > > It's not just a failed operation (expected to eventually fail), but > > something really went wrong, badly. > > Why it is different from any other failure? I.e. fopen("doesnotexist", > "r") produces false and it's not "hard failure". But if files were > objects, new File("doesnotexist", File::READONLY) suddenly becomes "hard > failure"? How the latter is harder than the former? I would say it's > exactly the same. If you say "new File" can only throw, you should also > say fopen() should only throw. If fopen can return error value, so can > File::open(), so can new File. > Excerpt from SplFileObject's manual page [1]: Throws a RuntimeException if the filename cannot be opened. [1] http://php.net/splfileobject.construct > The difference would be if File object would be built so that "new File" > should never fail, and opening would be done with "$file->open()" and > not with the ctor. But most of the object APIs in PHP are not written > this way - for these APIs, ctor failure is not something exceptional > more than failing to open file is exceptional. > > > Additionally, it makes no sense to have inconsistent behavior between > > internal classes and userland classes: it is currently impossible for a > > userland class to have the `new` operator producing an object that is not > > an instance of the class after that operator. > > That can be changed if needed. This is just a missing feature. > > -- > Stas Malyshev > smalyshev@gmail.com > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --047d7b6249984b8399050cfc8e79--