Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109017 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 90023 invoked from network); 14 Mar 2020 17:35:16 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Mar 2020 17:35:16 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8AD73180210 for ; Sat, 14 Mar 2020 08:57:09 -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.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) (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 ; Sat, 14 Mar 2020 08:57:08 -0700 (PDT) Received: by mail-qk1-f176.google.com with SMTP id h14so18320763qke.5 for ; Sat, 14 Mar 2020 08:57:08 -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=pvRI9doxvdCMRW84ygB+dg632uMid8BDdpRkS1oTJ/k=; b=MWceHVVUT+czUuWpoIE67ZeL+60tvkkDRAkIOPI2tx3rE2HRDs22XeGpZTv/OUymYM T55MfpH3QfKtr5/31psVIgAGGULjpeK2OFRjZGigMHw1ApYnglcmZ6aW1PMpc0nqt8Et Q1Ns+s6zUftYL/vzRQ1C8LkWgDkZX1uFJeOC4gzyCMytxogDw8Vl/rUA2O2s9cYbCs+A OND+qTjUACWkqq//50HokbLam7nd78zkSBbYUJgJCuNa7NCd+Ctk3dyxGSkAt9M3OPbe Vf3KGj+2cMH2ng0NH5KvDVQ0T88E4IhW/gCPRL2bWIVunZx1MA0u1tVEqPDog6MaaWcs YZ5w== 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=pvRI9doxvdCMRW84ygB+dg632uMid8BDdpRkS1oTJ/k=; b=PgF0Kpsun5wlaNigVkzkcgrKLaz2XcpkNgZML7NxPsuj1r3jHoUKn+YJ+q5K6TfML/ uRCGoYnuPc7HJeDZQUxU6vjHj3y9AJVMUs3H0KFjOmzxvfS8TUVVQp4bwtH5nD6xyeHV VdFO8JYRkv5lDteICKS969HYFmOysuveRvL+XwdPztJjwOGDn4s2F6WRbDgZz1xA8u7b Gt1L0v/1o83qQ0j6OoUtuGP/UNzE/CNmHL6p7M0/Rj4aS0MO645QdAoLVsNllZX6O3gq lN6asfgN6Txq0XbCb5s6cyo4zfARf42dycK9lijMWUDtn0sDCBM+jgcOxxAtZY0B2x+r AfIg== X-Gm-Message-State: ANhLgQ3jDqFS9UlJgSk0lZaxamrQPpvTW0U+dasTG9YF3hw1WTBfkVUj JwoebgRbuq/V6+JbqOhKEC2k1A== X-Google-Smtp-Source: ADFU+vsc1O3yotyao40f3HkFDw4BRt+Q2IR/oF1innHALHe9opjupdyxrdMwUlMdwrRl2Okf+7MD/Q== X-Received: by 2002:a37:678b:: with SMTP id b133mr18988285qkc.327.1584201427543; Sat, 14 Mar 2020 08:57:07 -0700 (PDT) Received: from ?IPv6:2601:c0:c680:5cc0:8db9:b81a:6f2c:7616? ([2601:c0:c680:5cc0:8db9:b81a:6f2c:7616]) by smtp.gmail.com with ESMTPSA id a186sm11534589qkg.2.2020.03.14.08.57.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 14 Mar 2020 08:57:07 -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: Sat, 14 Mar 2020 11:57:05 -0400 Cc: =?utf-8?Q?Midori_Ko=C3=A7ak?= , PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: References: To: "G. P. B." X-Mailer: Apple Mail (2.3445.104.11) Subject: Re: [PHP-DEV] Associated Arrays as function parameters From: mike@newclarity.net (Mike Schinkel) > On Mar 14, 2020, at 11:07 AM, G. P. B. = wrote: >=20 > On Sat, 14 Mar 2020 at 15:43, Midori Ko=C3=A7ak = wrote: >=20 >> Dear Internals, >>=20 >> I would like to as you a question. I know that it is possible to use = an >> array to function parameters like: function(...array); But this = method is >> not working when the array is associative. >>=20 >> Would not be fine if an array like ['param1'=3D>'value', 'param2' =3D> = 'value'] >> would be used in a function like function(param1, param2) regardless = of the >> order? >>=20 >> I think it would make our lives is easier. I'd be also happy if you = know if >> there is more effective method to achieve the same result. >>=20 >> Thanks, >> Midori >>=20 >=20 > What you are looking for are Named Parameters, there have been = multiple > RFCs about which have all been more or less abandoned from what I see. > https://wiki.php.net/rfc/namedparameters (=46rom 2012) > https://wiki.php.net/rfc/named_params (=46rom 2013) > https://wiki.php.net/rfc/simplified_named_params (=46rom 2016) Can anyone summarize why these did not move forward? =20 Nikita's proposal sounds pretty good IMO, and I think the follow up = proposal would have been nice, too. Any port in a storm! > On a side note, I don't think this feature is *that* useful and if you = get > to the point where you want to know which value you are passing to > which argument it seems, to me, that the function is having too many > arguments. Also IDEs exist and can tell you the name of the argument. I would assert a counter to your assertion that this feature would not = be *that* useful, at least several known use-cases. The known use-cases include: =20 1. Querying, be it SQL or some other query language. 2. Wrapping API calls (which is a form of querying.) 3. Instantiating properties of an object via __construct(). I assume most on this list are not fans of WordPress but that = notwithstanding WP_Query() is a good example of a class that accepts an = array of arguments on instantiation: - https://developer.wordpress.org/reference/classes/wp_query/ Unfortunately PHP can't type check those WP_Query() arguments, but it = could type check named parameters of a query() method. Yes, you can model all arguments as properties of an object, but then = how would you instantiate that class? Named properties would make doing = so much less tedious and allow it to be done in a single expression = rather than requiring multiple assignment statements. -Mike P.S. This would be on my top 5 list of features I would like to see = added in PHP 8. FWIW.=