Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80739 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 88064 invoked from network); 18 Jan 2015 12:41:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Jan 2015 12:41:49 -0000 Authentication-Results: pb1.pair.com header.from=marcio.web2@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=marcio.web2@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.49 as permitted sender) X-PHP-List-Original-Sender: marcio.web2@gmail.com X-Host-Fingerprint: 209.85.215.49 mail-la0-f49.google.com Received: from [209.85.215.49] ([209.85.215.49:49726] helo=mail-la0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 81/AB-18613-A0AABB45 for ; Sun, 18 Jan 2015 07:41:47 -0500 Received: by mail-la0-f49.google.com with SMTP id hs14so24908056lab.8 for ; Sun, 18 Jan 2015 04:41:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:reply-to:in-reply-to:references:from:date:message-id :subject:to:cc:content-type:content-transfer-encoding; bh=HkIwQLdWHmwD8FSKmPuYOyHD3jVx1FbWi0Ac9Q89ACg=; b=kqZz5GKE5DS0MK3N6yt6k8IJwhsWr/TB06IlZzU7BXDU0lTNSeOYzvs2xI7a4cWvKl D1eYhCSXv7E8EIPqxXWymROXyAzsMriV2PjRkY2rO4ZRcqUXfyNTjb+YKeScOIviXv/2 Kxm956pPg2O7jCSLTA016MDlKBodRZG+itVCeD+1OfDpg178njZuLtE1fc7xOuX1ed/Y b+mDWQM0HUMvWkB15qFc/uNP0sPRyGOepim9bZkomJd+6JAWH40Z8V1B89IBqt/zGqTZ 8HX4/fSwwIugoziJHSM4LE4jQXKUohs/0k3SxSFJYd8WHw51Ba24jn8GjvIcF2vg5N1Q mz2w== X-Received: by 10.112.167.136 with SMTP id zo8mr22499120lbb.17.1421584902997; Sun, 18 Jan 2015 04:41:42 -0800 (PST) MIME-Version: 1.0 Received: by 10.152.21.101 with HTTP; Sun, 18 Jan 2015 04:41:22 -0800 (PST) Reply-To: marcio3w@gmail.com In-Reply-To: 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> Date: Sun, 18 Jan 2015 09:41:22 -0300 Message-ID: To: Tony Marston Cc: PHP internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] Remove PHP 4 Constructors From: marcio.web2@gmail.com (Marcio Almada) > Perhaps there should be a new rule which says that invoking a constructor= with anything other than "new" or "parent::__contruct()" > should be illegal, in which case this situation would generate an error. Now this would break a lot of code that $obj->__construct(); or $this->__construct(); And I've seen a lot of it. 2015-01-18 9:33 GMT-03:00 Tony Marston : > "Andrea Faulds" wrote in message > news:D554C8B8-0BFB-44F7-B23E-8BFC12AE2930@ajf.me... >> >> >> Hey Rowan, >> >>> On 17 Jan 2015, at 19:40, Rowan Collins wrote= : >>> >>> On 17/01/2015 18:33, Todd Ruth wrote: > > > <> > > >>> I don't think using __construct over named-method for constructors real= ly >>> 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 benef= it 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= =99s 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. > > > If a developer cannot read valid code then it is a developer problem. It = is > not up to the language to dictate style - it provides the functions and > features while style and readability are the sole responsibility of the > individual developer. > >> This actually tripped me up on more than one occasion when updating test= s >> broken by the removal of PHP 4 constructors in php-src. > > > Perhaps this issue can be solved by the RFC on Default Constructors? See > https://wiki.php.net/rfc/default_ctor > >> 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! > > > Perhaps there should be a new rule which says that invoking a constructor > with anything other than "new" or "parent::__contruct()" should be illega= l, > in which case this situation would generate an error. > >> The following is much more obvious: >> >> parent::__construct(); >> >> I think it=E2=80=99s pretty clear why we changed to PHP5-style construct= ors. >> They=E2=80=99re just a lot more recognisable. :) >> -- >> Andrea Faulds >> http://ajf.me/ >> >> >> > > -- > Tony Marston > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >