Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107172 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 80456 invoked from network); 16 Sep 2019 17:20:29 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 16 Sep 2019 17:20:29 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 7B7A12CF1CB for ; Mon, 16 Sep 2019 07:57:24 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp3.php.net X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Virus: No Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp3.php.net (Postfix) with ESMTPS for ; Mon, 16 Sep 2019 07:57:23 -0700 (PDT) Received: by mail-io1-xd2f.google.com with SMTP id r26so79206023ioh.8 for ; Mon, 16 Sep 2019 07:57:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=fnu25QWS7uqEYBkuc0ACwjPNDZI7TfDI1iVLzCEKLNw=; b=p6cT8LyroaSlX2sWEAYtu8UKLOAChS8gdX+ieGy16zUXN+GrjJ/f3qzKurHQ7ABbfF xZCYT0IBNiGZQsu/hirr7K+ItuPOOZd+Y2+D2wWn6/2tQoOlR5qn4eDzTTOcJOrw2UjB 87BpRY6bLa/4+WlFYYKBC2PQYAlzqELAVI+mPPAfdV7f0Y2cj2Q9jvXRJJjcc/b3W/L9 qttlpPpj2MeIGvfTbbSvtDh3NntruHph7pTJjRCSLxqVaSyrwvnF6f72ZlXuyNsBxp2q otKUqSa94AXuGYkyqfHKZWQlr82XcHGNig1eMJ+GRU+MG8mm0A5ebnh6OlmIxtmlwdZ3 OEcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=fnu25QWS7uqEYBkuc0ACwjPNDZI7TfDI1iVLzCEKLNw=; b=ocz/aU4hXYagAQd3tX+5wTQKZrRrqcZE8NRgiN4Tj9yVCQ5646+13UyU0qrcBGYlip O8pUD140uDrASimCZTpbJnKTpheCzOJwVsxTdGpKluqS18OF7k++mMqjmx5yOT2PJTEf T3rm1HXQXQsKTrVXHWP848Xx0ZBSLqZhv558HMK6PW3WOsQujSk1pp/fo9N5vXxTZjT+ GBNFPALfNMe97iPmXkC2RZ+ataiRe7wVbH8dXc1T7Pz1HhDlRQzf1Sg3eBx7DQrWJzJv MYde5XFZDfzrdGJTZhhc134OtQB6cyLBQ62NCSGE+20GOaYMfVV62g0gdO/LiyYFCQ/6 oAOg== X-Gm-Message-State: APjAAAV3QNtkmSNwKq3J15eg1dktRV6KogJpa9puFo7l/mkHKJEmu3Mu UuD7oNE4i28jESFSz+eqXso/un5aBuiK2Q3ZRL0= X-Google-Smtp-Source: APXvYqxT9dJkNnRL0ATnWlTUohm8VfvYYGNID+SN8YQAvnRwTwRcQIm66ammP37iXXKVh9o0nnPuxlVCNmkV71gmbfg= X-Received: by 2002:a5e:a714:: with SMTP id b20mr327140iod.1.1568645832879; Mon, 16 Sep 2019 07:57:12 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 16 Sep 2019 15:57:01 +0100 Message-ID: To: =?UTF-8?Q?Micha=C5=82_Brzuchalski?= Cc: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000b6937e0592acd1fd" X-Envelope-From: Subject: Re: [PHP-DEV] Re: [RFC] Object Initializer From: rowan.collins@gmail.com (Rowan Tommins) --000000000000b6937e0592acd1fd Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, 16 Sep 2019 at 15:37, Micha=C5=82 Brzuchalski wrote: > > >> The problem with that is that you need an extra static method to make us= e >> of it, and you still need to get the arguments into that method. It migh= t >> be useful occasionally, but it still doesn't help constructors which are >> setting a large number of private / protected properties. >> >> > This RFC is not trying to help those constructors but tries to simplify > instantiation objects and initializing properties > there where any kind of constructor won't help, but rather would be > unnecessary at all. > I realize that, I was responding to a specific point: you said that the syntax would work for protected or private properties if used where those are visible. I was saying that I don't think that combination would be used very often, so it's easiest to just discuss the public property case. > You wouldn't want to put 15+ arguments in your constructor to initialize > public properties which > don't need other validation than proper type, right? > > Even if it would be just adding "public" keyword in front of them. > Why not? You've got to list those 15 properties somewhere; if the syntax was such that you only needed to list them once, it makes no difference whether we call the result "class initializer" or "automatic constructor with 15 named parameters", IMO. > > >> Either of those, with named parameters, would be almost indistinguishabl= e >> from object initializers at the call site. Depending on the syntax chose= n, >> it might be as similar as: >> >> // Call initializer, requires public properties >> new Employee { age =3D> 42, name =3D> 'John Smith' }; >> // Call constructor, requires special constructor definition >> new Employee( age =3D> 42, name =3D> 'John Smith' ); >> >> > Last RFC treating about named arguments has similar syntax with curly > braces, but all together with previous ones > tries to solve the issue through additional syntax inside parentheses, > which means both features can coexist together. > > Calling instantiation always used parentheses as the way to pass > constructor arguments let's keep it that way. > Using object-initializer would use curly braces - just like it's used to > be solved in other languages. > My intention here was just to show that using named parameters would be just as concise as using an object initializer; I just picked a pair of syntaxes that were as similar as possible to illustrate that. > > >> >> That would require multiple new features, though, so initializers might = be >> more achievable in the short term, and perhaps there is room for both, >> particularly if support for getters and setters improves. >> >> > Here again, IIRC you're trying to solve the issue which is off-topic. > Improving protected and private properties initialization through > constructor is not the main target of current RFC. > I don't think it's off-topic to consider whether a related feature would make this one redundant. However, you've picked a weird sentence to reply to, because I'm agreeing with you, that the two features could exist side by side without being redundant. Regards, --=20 Rowan Tommins [IMSoP] --000000000000b6937e0592acd1fd--