Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80714 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 27958 invoked from network); 18 Jan 2015 01:50:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Jan 2015 01:50:45 -0000 Authentication-Results: pb1.pair.com header.from=ocramius@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ocramius@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.51 as permitted sender) X-PHP-List-Original-Sender: ocramius@gmail.com X-Host-Fingerprint: 74.125.82.51 mail-wg0-f51.google.com Received: from [74.125.82.51] ([74.125.82.51:63228] helo=mail-wg0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 50/51-18613-3711BB45 for ; Sat, 17 Jan 2015 20:50:44 -0500 Received: by mail-wg0-f51.google.com with SMTP id l18so4259339wgh.10 for ; Sat, 17 Jan 2015 17:50:40 -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=buxSPDh2XWpUFr/EmRD+ajqd9P9SgqPKfl0wfRP3zvw=; b=j/P6Q/fOB/q7t6oES4T7aCHwNLMJl8pVAGrD5PTroDbpTkfKH4KKuVCQPiL8y4qLPt s5vicn+z0w3WrH/HWsrPJCJw+JWgoRSvogh1BTBpM6Ew2qj++cOaUJ0U249P3MdvJ0yj QFMmhq+7RARhOayH9aym21GptS0wyvgod8mp4t0R6JBtjUKXg31ea0cYB0rjuP8o+1Vq oPQhRMLL2P3e4oQIoGn7jWF2oQkxDA/4gwGpJQMxmvRj8X3LFWAJQz9ijSECDyRl/0Fl igZei2vUL8XJSsVg1qRyMZUkghMFbJerKd1m/6D15lWZa8vdQ3nLjI4IzuAgz+Ur00/t WEvQ== X-Received: by 10.194.190.10 with SMTP id gm10mr42836553wjc.91.1421545840479; Sat, 17 Jan 2015 17:50:40 -0800 (PST) MIME-Version: 1.0 Received: by 10.194.82.163 with HTTP; Sat, 17 Jan 2015 17:50:20 -0800 (PST) In-Reply-To: <003201d0326b$6fd27f60$4f777e20$@tekwire.net> References: <003201d0326b$6fd27f60$4f777e20$@tekwire.net> Date: Sun, 18 Jan 2015 02:50:20 +0100 Message-ID: To: francois@tekwire.net Cc: Dan Ackroyd , PHP Internals List Content-Type: multipart/alternative; boundary=047d7bea39f4da966b050ce36e12 Subject: Re: [PHP-DEV] Class constructor behaviour From: ocramius@gmail.com (Marco Pivetta) --047d7bea39f4da966b050ce36e12 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 17 January 2015 at 16:37, Fran=C3=A7ois Laupretre wrote: > > De : Dan Ackroyd [mailto:danack@basereality.com] > > > > This is pretty horrible and should be fixed by making sure that > > constructors either return an object or throw an exception. > > Additionally the exception policy for core (that was previously > > discussed here: http://marc.info/?t=3D119263748000001&r=3D1&w=3D2 ) sho= uld > > be updated so that any constructor returning NULL is considered a bug, > > no matter what the ini settings are. > > I would prefer deciding that returning null is the standard way for a > constructor to inform the PHP core that the object creation failed (for a= ny > reason). This would be trapped by the core and cause a catchable fatal > error. > 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. An exception fits perfectly in this case. 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. It feels weird, from a user perspective, to have `new` producing non-object values. The general feeling when dealing with cases such as PDO's constructor is "WAT?!". Therefore gogogo Danack! Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ --047d7bea39f4da966b050ce36e12--