Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:68454 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 70659 invoked from network); 8 Aug 2013 19:17:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Aug 2013 19:17:35 -0000 Authentication-Results: pb1.pair.com header.from=martin.keckeis1@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=martin.keckeis1@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.219.45 as permitted sender) X-PHP-List-Original-Sender: martin.keckeis1@gmail.com X-Host-Fingerprint: 209.85.219.45 mail-oa0-f45.google.com Received: from [209.85.219.45] ([209.85.219.45:44335] helo=mail-oa0-f45.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 36/00-06453-ECEE3025 for ; Thu, 08 Aug 2013 15:17:34 -0400 Received: by mail-oa0-f45.google.com with SMTP id m1so5933425oag.32 for ; Thu, 08 Aug 2013 12:17:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=e5/lmnYXRguOKlodN6w4kaGax3S80nnB/wurdCtDPmc=; b=vf/71BPi2PKU3J2IDBkZ39IQ3V4Db5aBUFrpcLlaWylvUM8A+xZHw4edn/Ayh/Wfno +R5rbO2ub1tuXDLW0Pzr1rn77cGtsizVkeQu1xW69XYGhl+e++GuOZAVV3fpYHjyAS9F UcAatxbXfTPTGwT1ZnSOQ0QgF8zQtSudTEQ2pKh853ZzR5s1nBvFymFu1V/OI7CQB/FO snbQdkqA1P9W65S+3aPcRKD0mZQxj2vbnLNwDmN28aBXHiNFq0+FvVQ/BOJs0tamgo3z E8fMwTYtY5f3m5XLFfp76OjQ4AcBc3vbFwe2xHSXjmZUbeM9iy9QWfbuX8k7k6VP6/d4 41kA== MIME-Version: 1.0 X-Received: by 10.182.106.4 with SMTP id gq4mr361016obb.4.1375989452046; Thu, 08 Aug 2013 12:17:32 -0700 (PDT) Received: by 10.182.26.112 with HTTP; Thu, 8 Aug 2013 12:17:31 -0700 (PDT) Received: by 10.182.26.112 with HTTP; Thu, 8 Aug 2013 12:17:31 -0700 (PDT) In-Reply-To: References: <52037411.7070406@seld.be> Date: Thu, 8 Aug 2013 21:17:31 +0200 Message-ID: To: Matthieu Napoli Cc: PHP internals Content-Type: multipart/alternative; boundary=e89a8fb1fa6281074504e3748265 Subject: Re: [PHP-DEV] RFC: constructor argument promotion From: martin.keckeis1@gmail.com (Martin Keckeis) --e89a8fb1fa6281074504e3748265 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Am 08.08.2013 15:12 schrieb "Matthieu Napoli" : > > Le 08/08/2013 13:11, Martin Keckeis a =C3=A9crit : > >> Am 08.08.2013 12:34 schrieb "Jordi Boggiano" : >>> >>> >>> On 08.08.2013 10:34, Leigh wrote: >>>> >>>> I'm not sure what problem this is really trying to solve, the >> >> boilerplate >>>> >>>> code you mention is very explicit and it is very clear to the reader >> >> what >>>> >>>> is being done. Each property documented with its type, purpose and >>>> visibility in a common place for easy reference (at the top of the >> >> class). >>>> >>>> Each property that takes a value from the constructor assigned in the >>>> constructor. Very clear. >>> >>> >>> I for one am pretty tired of writing this boilerplate in every second >>> class I write. Using dependency injection you end up having to write a >>> LOT of those usually, and constructors typically only contain assignments. >>> >>> Adding a property means: declaring the property, adding the ctor arg, >>> adding the assignment in the ctor. You have to write the property name = 4 >>> times. With this RFC in it'd come down to writing it once, and would >>> avoid having undeclared properties because someone forgot. >>> >>> I am very supportive the idea, although I see that it could be confusin= g >>> to some. Maybe the syntax needs to change, but the overall change is >>> much welcome. >> >> >> The syntax itself i feel is self explaining. You read it and you know whats >> going on. >> >> But somehow i feel this is "wrong". Declaring visibility directly in the >> arguments? This looks very scary to me. (Maybe only because i've never seen >> it before...) >> >> Other reasons against: >> Phpdoc generator break >> Code completion break >> If constructor is not at the beginning never see a var declaration >> Auto generation of set/get can be achieved with IDE..so its not much wor= k > > > I second the feeling about the syntax, there are too many disadvantages. However the idea is excellent. > > Maybe an alternative approach could do, here is a random suggestion (a bit more verbose): > > class MyClass { > public $foo; > protected $bar; > > public function __construct($this->foo, $this->bar, $baz) { > // $this->foo and $this->bar are now set > $baz->doAnything(); // $baz is a standard parameter > } > } > > This would even be compatible with an interface: > > interface MyInterface { > function __construct($foo, $bar, $baz); > > } Another thing which came into my mind: I normall create a set/get method also to a construct parameter to overwrite and unittest it... So then i cant use this, because i construct i also use the set mehod to be sure the var is assigned always the same (e.g. additional input check or exceptions) --e89a8fb1fa6281074504e3748265--