Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80709 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 10751 invoked from network); 17 Jan 2015 20:20:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Jan 2015 20:20:59 -0000 Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 192.64.116.200 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.200 imap1-2.ox.privateemail.com Received: from [192.64.116.200] ([192.64.116.200:35655] helo=imap1-2.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 42/00-10522-D14CAB45 for ; Sat, 17 Jan 2015 15:20:58 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id 571D2B0007B; Sat, 17 Jan 2015 15:20:42 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at imap1.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap1.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id q9jt3weSH6UH; Sat, 17 Jan 2015 15:20:42 -0500 (EST) Received: from oa-res-26-240.wireless.abdn.ac.uk (oa-res-26-240.wireless.abdn.ac.uk [137.50.26.240]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id 337B1B00068; Sat, 17 Jan 2015 15:20:40 -0500 (EST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.1 \(1993\)) In-Reply-To: <54BABA93.9070809@gmail.com> Date: Sat, 17 Jan 2015 20:20:36 +0000 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: References: <0DD30A0D-E7CA-4150-83E0-8FD46635279C@ajf.me> <8761c6280g.fsf@margaine.com> <54B91D16.70901@gmail.com> <78.22.47555.7C24AB45@pb1.pair.com> <1421519637.40188.1.camel@proposaltech.com> <54BABA93.9070809@gmail.com> To: Rowan Collins X-Mailer: Apple Mail (2.1993) Subject: Re: [PHP-DEV] [RFC] Remove PHP 4 Constructors From: ajf@ajf.me (Andrea Faulds) Hey Rowan, > On 17 Jan 2015, at 19:40, Rowan Collins = wrote: >=20 > On 17/01/2015 18:33, Todd Ruth wrote: >>> As already mentioned I think as an end result we shouldn't have two >>> >ways to define constructors. Given that PHP already prefers the >>> >new-style constructors I've proposed that we work towards dropping = the >>> >old-style, it's just down to a matter of how. >> I've been following these threads for about 10 years and beg that php >> internals continues to "live and let live". >> There have been many, many threads over the years from what I would = call >> (with obvious bias) "OO fundamentalists". They seem to be at war = with >> code that is "bad form". >=20 > This is an argument that comes up a lot, and it has some merit, = sometimes. >=20 > I don't think using __construct over named-method for constructors = really has anything to do with "OOP fundamentalism"; it was a design = change to make certain things simpler (like parent::__construct), and = more consistent (all reserved magic methods begin with __, so any method = not beginning with that is safe to use however you like). To add on to what you said, there=E2=80=99s also a quite important = benefit that __construct is a lot more obvious in what it does. Looking at the following code: class Foo { public $foo, $bar, $qux; public function foobar() { // ... } public function bar() { // ... } public function foo() { // ... } public function baz() { // ... } public function qux() { // ... } } It=E2=80=99s not easy to spot the constructor at a glance, and it=E2=80=99= s very easy to miss. Compare that to the following: class Foo { public $foo, $bar, $qux; public function foobar() { // ... } public function bar() { // ... } public function __construct() { // ... } public function baz() { // ... } public function qux() { // ... } } Far more obvious. This actually tripped me up on more than one occasion = when updating tests broken by the removal of PHP 4 constructors in = php-src. Sure, the constructor should probably be the first method, but = *even if it is* it=E2=80=99s still nowhere near as obvious in PHP 4 = style. Similarly, what does the following do? $this->foo(); It looks like a normal method call, and it is in a sense. But if = you=E2=80=99re in Bar and inheriting from Foo, that=E2=80=99s a call to = the parent class=E2=80=99s constructor! The following is much more obvious: parent::__construct(); I think it=E2=80=99s pretty clear why we changed to PHP5-style = constructors. They=E2=80=99re just a lot more recognisable. :)=20 -- Andrea Faulds http://ajf.me/