Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80769 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69309 invoked from network); 19 Jan 2015 05:48:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Jan 2015 05:48:23 -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.214.171 as permitted sender) X-PHP-List-Original-Sender: smalyshev@gmail.com X-Host-Fingerprint: 209.85.214.171 mail-ob0-f171.google.com Received: from [209.85.214.171] ([209.85.214.171:62241] helo=mail-ob0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EA/B0-64889-6AA9CB45 for ; Mon, 19 Jan 2015 00:48:22 -0500 Received: by mail-ob0-f171.google.com with SMTP id va2so17367283obc.2 for ; Sun, 18 Jan 2015 21:48:19 -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=NHGSt4WGpUjFooYud9yk5ba/KhPQ2+8SuDa8LCZ6zho=; b=AvLK1t7VfBRXr9wSSGHeBd9SZdA+Q3P9XS6qBPorj9RbXDcpf2uD9RbpDU2+ktKV9v Hid4cgoptzuTvx2O+fIvouEMgGiSDaXBLhvjzB8AEvF0Bo3ulV4CQKccF9w132aSF+tj SVJNzm/0pOOtGyoIYacbuFiODLS8VzEX/TfJhF1ZBtjFyO1Q2CmF4eiJXjxH96B4hN4A EfK7b3Vb8o+AktAKpwQefrjEDPUwAXq4F0o1svk+7YZg08s0wl8WCMQJD5e1sSnEecMB 1eF3gnLBCwPBTScdkjZLStI1zPMMbylViC+VU6TjgPNZixoTgScPQzyfcrXYXnAmql1J ibhw== X-Received: by 10.60.61.75 with SMTP id n11mr17086828oer.22.1421646499027; Sun, 18 Jan 2015 21:48:19 -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 h9sm5509673obw.1.2015.01.18.21.48.17 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 18 Jan 2015 21:48:18 -0800 (PST) Message-ID: <54BC9A97.9020103@gmail.com> Date: Sun, 18 Jan 2015 21:48:07 -0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: Marco Pivetta , francois@tekwire.net CC: Dan Ackroyd , PHP Internals List References: <003201d0326b$6fd27f60$4f777e20$@tekwire.net> In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Class constructor behaviour From: smalyshev@gmail.com (Stanislav Malyshev) 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. 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