Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:54237 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 23448 invoked from network); 28 Jul 2011 20:09:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Jul 2011 20:09:10 -0000 Authentication-Results: pb1.pair.com smtp.mail=rquadling@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rquadling@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.42 as permitted sender) X-PHP-List-Original-Sender: rquadling@gmail.com X-Host-Fingerprint: 209.85.216.42 mail-qw0-f42.google.com Received: from [209.85.216.42] ([209.85.216.42:61869] helo=mail-qw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 32/FD-35879-5E1C13E4 for ; Thu, 28 Jul 2011 16:09:10 -0400 Received: by qwi4 with SMTP id 4so1742320qwi.29 for ; Thu, 28 Jul 2011 13:09:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:reply-to:in-reply-to:references:from:date:message-id :subject:to:cc:content-type:content-transfer-encoding; bh=/OLDgNSiEysKubpFUKUh1+MHnm14cfCpvOfv6lBfHx0=; b=Nz1Q0lAW4Z8JfZjNtZxqQaeEwIgsZErBipS8oKlQ9btdBvqIEf7aEBDnxQWTUFlS2z 2bcxbqZIyWMHwUJiuH8rOB1kIe+35gla+2QbV+kRfbX1U8rE1aaCq+24rtFKxRp3sxT0 ovGZZWD6AnNxhsZdsPcc6ZxINWAyJM93k6kXM= Received: by 10.229.217.72 with SMTP id hl8mr379945qcb.65.1311883747141; Thu, 28 Jul 2011 13:09:07 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.81.14 with HTTP; Thu, 28 Jul 2011 13:08:47 -0700 (PDT) Reply-To: RQuadling@GMail.com In-Reply-To: References: <4E31328C.9030208@mageekbox.net> Date: Thu, 28 Jul 2011 21:08:47 +0100 Message-ID: To: John Crenshaw Cc: Etienne Kneuss , "frederic.hardy@mageekbox.net" , 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: rquadling@gmail.com (Richard Quadling) On 28 July 2011 20:36, John Crenshaw wrote: > > > 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 b= e 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 n= ew >> behavior, because moked \DirectoryIterator class does not call the paren= t >> constructor. >> In context of unit test, the fact that \DirectoryIterator is inconsistan= t >> may be not a problem and can be the desired behavior. > > I strongly agree. Throwing an exception ONLY because the parent construct= or wasn't called is a serious departure from expectations. It is fine for o= ther code in the parent class to fail later due to incomplete/improper init= ialization which may likely be caused by failure to call the parent constru= ctor earlier, (In fact, that is even expected in many cases) but I cannot c= onceive of any acceptable reason for the error described here. Even though = the change was certainly well intentioned, it clearly didn't account for th= e possibility of unusual but valid coding situations (such as mocks and oth= er code generation tactics that should be able to reasonably depend on cons= istent language behaviors). If the constructor MUST be called, then it would seem that you must not be allowed to extend it and instead, have another method which you must use. Badly, beforeConstruct() and/or afterConstruct(), but then we are moving to AOP (which would be nice). Enforcement of the constructor can only be achieved by making it final. --=20 Richard Quadling Twitter : EE : Zend : PHPDoc @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea