Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86733 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 6272 invoked from network); 17 Jun 2015 13:25:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Jun 2015 13:25:59 -0000 Authentication-Results: pb1.pair.com header.from=sbj.ml.read@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=sbj.ml.read@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.171 as permitted sender) X-PHP-List-Original-Sender: sbj.ml.read@gmail.com X-Host-Fingerprint: 209.85.213.171 mail-ig0-f171.google.com Received: from [209.85.213.171] ([209.85.213.171:35110] helo=mail-ig0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5D/50-02966-46571855 for ; Wed, 17 Jun 2015 09:25:56 -0400 Received: by igbzc4 with SMTP id zc4so102860505igb.0 for ; Wed, 17 Jun 2015 06:25:54 -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=zNy2Z0sgE/5Mqj6WDF/bAcAsk7r0Ik4FnRLCO+sbb4k=; b=lQ8CMUrZiutEKII5XX0XzH9ThcC0IBTo8U4MA6PNcWb65FNsh0eHIAVkooSHMSNGuY FFbk1U8wWAlCRT6djawGoKMdAhLMT9FBmDyJgXocKL2ZEPBaJu68U249j3XZf+9Mzuzj M7p2p8m2Dmde4Hfhf0wKf88UnUKJ5Tsp0THkvEMVQIghln2q29r/8cbQwHyk7X8DbbZ9 TyihiBcJa3zl69sfeKePZUyJp3yppX+OpFjPtqEwMw+ucxsWsP+wnfzNxYGlq5/glUcM 8hBNiw7iWQ+6ZESxH4iW5lmLQMJ0ZKWFrhbryocXU61NuSX7ccv00ngROTJI+wTofDsJ RDcw== MIME-Version: 1.0 X-Received: by 10.107.163.146 with SMTP id m140mr8193331ioe.85.1434547554120; Wed, 17 Jun 2015 06:25:54 -0700 (PDT) Received: by 10.107.181.194 with HTTP; Wed, 17 Jun 2015 06:25:54 -0700 (PDT) Received: by 10.107.181.194 with HTTP; Wed, 17 Jun 2015 06:25:54 -0700 (PDT) In-Reply-To: <1434543855.21120.37.camel@kuechenschabe> References: <1434543855.21120.37.camel@kuechenschabe> Date: Wed, 17 Jun 2015 15:25:54 +0200 Message-ID: To: =?UTF-8?Q?Johannes_Schl=C3=BCter?= Cc: Lorenzo Fontana , PHP internals Content-Type: multipart/alternative; boundary=001a113bb0d8607d2e0518b6a14c Subject: Re: [PHP-DEV] Initializer List From: sbj.ml.read@gmail.com ("Sebastian B.-Hagensen") --001a113bb0d8607d2e0518b6a14c Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi, the proposed syntax also clashes with the new return type hints. They don't make sense on construct, but reusing the same syntax for two different things should be avoided if possible. Hack implements a related approach (without most of the c++ guarantees and benefits as it is pure syntactic sugar). If php wants to have something similar, it may be favorable to talk to them why they chose to implement it the way they did. http://docs.hhvm.com/manual/en/hack.constructorargumentpromotion.php Regards, Am 17.06.2015 14:25 schrieb "Johannes Schl=C3=BCter" : > > On Wed, 2015-06-17 at 10:03 +0200, Lorenzo Fontana wrote: > > - In C++ using initializer list is used over assignment also for > > performance reasons but right now I can't say if this can be achieved i= n > > PHP or not. > > > > Initializer lists in C++: > > http://en.cppreference.com/w/cpp/language/initializer_list > > Mind that C++ doesn't do this to make code "nice" or "short" or whatever > in that area but primarily due to need of control. Not having > initializer lists means that object members in C++ have to be default > constructible. Given C++ code like this > > struct C { > SomeType a; > C(const SomeType& a) { > this->a =3D a; > } > } > > first calls the default constructor SomeType::SomeType() for a and then > the assignment constructor (SomeType::operator=3D(const SomeType&) or > similar) > > Another reason why C++ needs this ist const-correctness. In the example > above it will fail if a is marked as const as the default constructor > will initialize and assignment on const objects isn't valid. > > In PHP however the default constructor equivalent is setting the type to > NULL which is (almost) for free while allocating the variable. Thus the > need isn't there. > > You also write > > > public function __construct() : host("127.0.0.1") {}; > > as example. But that ignores PHP's way to define default values: > > class Foo { > private $host =3D "127.0.0.1"; > } > > would be the PHP version to what you propose. At the same time I am > confussed, by using a literal string there I assume you want to allow > expressions there, but in other examples, like > > > public function __construct($name, $surname, $age) : name(name), > > surname(surname), age(age) {}; > > you are not handling expressions (unless the constructor arguments are > being ignored and properties are being initialized using the global > constants name, surname and age, which I assume you didn't intend) > > You are also not discussing inheritance. Can I do > > class Base { /* .... */ } > class Extended extends Base { > public function __construct() : parent(42) {} > } > > how does that relate to parent::__construct()? > > > In summary: > I consider this syntactic sugar which in my opinion doesn't increase > readability and in other languages solves an issue PHP doesn't have. > > johannes > --001a113bb0d8607d2e0518b6a14c--