Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:54235 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 2482 invoked from network); 28 Jul 2011 18:25:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Jul 2011 18:25:25 -0000 Authentication-Results: pb1.pair.com smtp.mail=ekneuss@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ekneuss@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.161.42 as permitted sender) X-PHP-List-Original-Sender: ekneuss@gmail.com X-Host-Fingerprint: 209.85.161.42 mail-fx0-f42.google.com Received: from [209.85.161.42] ([209.85.161.42:38286] helo=mail-fx0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 32/9A-35879-499A13E4 for ; Thu, 28 Jul 2011 14:25:24 -0400 Received: by fxe23 with SMTP id 23so1709399fxe.29 for ; Thu, 28 Jul 2011 11:25:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=ICwuKgx7AySNw2/jxt8p0z3PqPgG4O3pHR9CvL4SsGA=; b=qvgM3ZmGqDbwmG9RcqT0Zv506NOcv04750QxK1VLI8ZhfKbRmNuRcm4ACI39pI4g8u MivDvvZzsIQmSXW2j8UaDcYOddEKw3NVE9r4MhxIUEzpwaI0SePOR/jJec7bs7K9PGoX gUkF5BACsDZDnG1udtnoqNSrOHfg6WC+mBHKk= MIME-Version: 1.0 Received: by 10.204.48.208 with SMTP id s16mr110180bkf.167.1311877520742; Thu, 28 Jul 2011 11:25:20 -0700 (PDT) Sender: ekneuss@gmail.com Received: by 10.204.122.80 with HTTP; Thu, 28 Jul 2011 11:25:20 -0700 (PDT) In-Reply-To: <4E31328C.9030208@mageekbox.net> References: <4E31328C.9030208@mageekbox.net> Date: Thu, 28 Jul 2011 20:25:20 +0200 X-Google-Sender-Auth: 7JoKgjyYACWEPTShpChAGEgcTew Message-ID: To: frederic.hardy@mageekbox.net Cc: PHP Internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Exception throwed if parent::__construct() not called in \DirectoryIterator subclass From: colder@php.net (Etienne Kneuss) Hello, 2011/7/28 Fr=C3=A9d=C3=A9ric Hardy : > Hello ! > > In PHP 5.4 alpha, an exception is throwing if a subclass of > \DirectoryIterator not called the parent constructor. > Moreover, this exception can not be catched in the constructor of the > subclass. > This behavious seems to be a good idea, because \DirectoryIterator may be= in > an inconsistant state if the parent constructor is not called. > But i think that it's not a good idea, because it's a BC break. > It's not the case in 5.3 and i have unit test cases which fail by this ne= w > behavior, because moked \DirectoryIterator class does not call the parent > constructor. > In context of unit test, the fact that \DirectoryIterator is inconsistant > may be not a problem and can be the desired behavior. We have two ways internally of execute code that needs to be executed as soon as we instantiate the object: 1) In the constructor 2) In the handler managing instantiation. Doing it in (1) is problematic as PHP gives no implicit guarantee that it will be called. Doing it in (2) is also problematic as it makes the class "magic", by putting code with effects in a place where it doesn't belong. From a design perspective it is better to execute such code in the constructor, especially if it takes argument, so (1) is "more correct" than (2). Now, as I said, PHP does not force you to call the parent constructor. In almost every cases, not calling the overridden constructor is bad practice and yields inconsistent results. For internal classes, skipping code that often do mostly initialization is dangerous and leads to crashes. Now, for the issue at hand: Even though it is a BC break, I believe that it is a very small one and that it should be seen as a bug fix. Note that the restriction is only here if the user tries to do something terribly wrong. IMO, it should remain impossible to extend DirectoryIterator's __construct without calling the parent construct. Best, > > There is a bug report : https://bugs.php.net/bug.php?id=3D55300 > > Best regards, > Fred > -- > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > Fr=C3=A9d=C3=A9ric Hardy : Architecte d'application/Admin. syst=C3=A8me/E= rgonome > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 CV : http://blog.mageekbox.net/public/= cv.frederic.hardy.pdf > =C2=A0 =C2=A0 =C2=A0 =C2=A0 Blog : http://blog.mageekbox.net > =C2=A0 =C2=A0 =C2=A0Twitter : http://twitter.com/mageekguy > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --=20 Etienne Kneuss http://www.colder.ch