Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110049 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 98605 invoked from network); 6 May 2020 21:13:43 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 May 2020 21:13:43 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D06BF1804F2 for ; Wed, 6 May 2020 12:48:53 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.172]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 6 May 2020 12:48:53 -0700 (PDT) Received: by mail-qt1-f172.google.com with SMTP id q13so2611685qtp.7 for ; Wed, 06 May 2020 12:48:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=TiBRyd32lhpmLS5uw5iAnfZ6AqBQsNv2cYaOyigWlrc=; b=iMVbaEkI61Wb2sqHOETJXUyqGCXxzX1AfCqCfPobhFNSwu8tO90MS2MUJnorIlncC7 LBIzW+P/p5KDhWWcnCqbuLF5BJbUjokoXXVWzwxddo6PSLP9QrRCDK5YSMq3fx2RXAHm e/t+nfFtdxUPCyXc6ICOarM4X9Dp68w6jIE2J68Bi3mb1F1+xn75ky8TpdDuV5aolfN9 ONKJ1aiYeDXp2NJiz/v828ykS3twqzljHovdyDpsmuEZIWbgLho8ekgjywuuBZPEhzur W4iU3HCQLByheodcO0l3uCuzJGQIGqsjlJG0BefCEAtTLraEz0T1zm7BpuTVxLBmWrZX zhLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=TiBRyd32lhpmLS5uw5iAnfZ6AqBQsNv2cYaOyigWlrc=; b=b/33fYz689uQuaRQl071ls/4Q5QiQ7jxa6/3AUYzWGbTd35+38Z3Kh29Hl2GZ5WZ0r qfAo0TYrckCGNx0yYjpzwtR9kKT+l/50GH1MbwizbodEes1lsjZA0kOtq+YGvjV1Ehl8 iaOrLruIbVv7Cx7MkHwOrZhF/EU/NNTBYJio/yTkb3vXHAE2Dg/ixuaV0fs7bnINPPFS R8Pc11Jo+pYAreVzF4lPfoM0SBeto9zhLNg1u2Zd/2epkpL+hwqHkvKx094ae12meZau 145my9WbvFQxAnYwlwWLpL9cj48Ffkvy7cSb183r3sRw7fDlrnzYFxLenCdb9OzIk+Ns UVPA== X-Gm-Message-State: AGi0PuZpemzUJ6itgI9QynSuGwxVktWFF46iE1A6JDyiexiNSJzq20NO U3zk3yFxuBBIk4fRz1b4jFtTWA== X-Google-Smtp-Source: APiQypJMz32hXxHJ7Y1U8dlj/rmn4nvBId5Gy4/KkoMn84QumHxLSC9RhqvRlqc8uWKbnYaMwn5zCw== X-Received: by 2002:ac8:1885:: with SMTP id s5mr9976707qtj.253.1588794532468; Wed, 06 May 2020 12:48:52 -0700 (PDT) Received: from ?IPv6:2601:c0:c680:5cc0:f08a:3d5:11af:903? ([2601:c0:c680:5cc0:f08a:3d5:11af:903]) by smtp.gmail.com with ESMTPSA id b11sm2228638qti.50.2020.05.06.12.48.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 May 2020 12:48:51 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) In-Reply-To: Date: Wed, 6 May 2020 15:48:50 -0400 Cc: PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: <1C09C0A9-1DA4-4753-8E5A-A739D52DA0B3@newclarity.net> References: To: Nikita Popov X-Mailer: Apple Mail (2.3445.104.11) Subject: Re: [PHP-DEV] [RFC] Parameter Blocks (vs. Constructor Property Promotion and Named Parameters) From: mike@newclarity.net (Mike Schinkel) > On Mar 26, 2020, at 9:30 AM, Nikita Popov = wrote: >=20 > Hi internals, >=20 > I would like to submit the following RFC for your consideration: > https://wiki.php.net/rfc/constructor_promotion >=20 > This is based on one off the suggestions made in > https://externals.io/message/109220, and some existing discussion on = the > topic can be found in that thread. >=20 > The primary motivation for this feature is to close the currently = rather > wide gap between the use of ad-hoc array structures, and the use of > well-defined and type-safe value objects. The latter is what we want = people > to use, but the former is, unfortunately, what is *easy* to use. >=20 > Regards, > Nikita I am rather concerned about constructor promotion will result in some = complex "single" lines of code that all must be syntactically correct = for any of it to be syntactically correct. It will make it more = challenging to read and write code as we add attributes and PHP doc to = properties. And if we still have to deal with concern that parameter = names that were previously never indented to become part of the API will = be exposed as part of the API, with potential breakage when name = changes. Pondering these issues I think I have a very simple proposal that would = address most (all?) of the concerns I am aware for both Constructor = Property Promotion and Named Parameters. =20 Consider simply what we might call "Parameter Blocks." Since PHP always = expects a parentheses to follow the function or method name it should be = possible to opt-in replace it with a brace-enclosed block of parameters = instead since it would be unambiguous and this no conflict, and no need = for new keywords. =20 The following illustrates how it my be used by repurposing an example = from the RFC: abstract class Node { public function __construct{ /** * @param Location|null =E2=80=94 The starting location for this = abstract node */ Location $startLoc =3D null; protected Location $startLoc =3D null; /** * @param Location|null =E2=80=94 The ending location for this = abstract node */ protected Location $endLoc =3D null; } {} } =20 class ParamNode extends Node { public function __construct{ /** * @param string $name =E2=80=94 Names this Node. */ public string $name; /** * @param ExprNode|null $default =E2=80=94 Contains the = expression this node represents=20 */ <> public ExprNode $default =3D null; /** * @param TypeNode|null $type =E2=80=94 Contains the type = expected for this node's expression */ <> public TypeNode $type =3D null; /** * @param bool $byRef =E2=80=94 True if this node is a = reference, false otherwise */ public bool $byRef =3D false; /** * @param bool $byRef =E2=80=94 True if this node is variadic, = false otherwise */ public bool $variadic =3D false; /** * @param Location|null =E2=80=94 The starting location for this = node */ Location $startLoc =3D null; /** * @param Location|null =E2=80=94 The ending location for this = node */ Location $endLoc =3D null; } { parent::__construct($startLoc, $endLoc); } } Envision how that same code would have to be written if all as part of = the single "line" contained within the parenthesis of a programming = language? =20 As far as I can tell this is a clean and elegant approach with many = fewer downsides than those that have been discussed thus far. I hope = that each of you reading this will seriously consider this is viable = alternative option. -Mike