Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110962 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 16440 invoked from network); 12 Jul 2020 11:33:32 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 12 Jul 2020 11:33:32 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4A1501804DA for ; Sun, 12 Jul 2020 03:25:27 -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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from sender4-op-o11.zoho.com (sender4-op-o11.zoho.com [136.143.188.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 12 Jul 2020 03:25:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594549523; cv=none; d=zohomail.com; s=zohoarc; b=BQ7OQ6fLtEFiKPkJFzRselqYNhMNByCKgMeMsTAUY3LGxWwflrvDUX1Q7gzvriM+q04jlx+UKeF7CWtIeDmiJYSHw8ekPKuGJ53v5B0c1UPNEABG1PO4K0i+d37fMXawmPW4P4C6gzPtRS6HXCMWdc/JgSU9tfO0n2qkJ/DZ5sw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594549523; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=XHRCV/SkpUlnUrwp7YKRMr4hCbFOWpMU0u90AAzPwZ0=; b=PKas37T+6PufiRIcPKepVX9Z9Aq+4QmdIAu9njmN2C0ymkv0wGlUvDuOq7xNyArX7GqmIcPYsqlC/ziqggKyTykKxi/VOWzvduleMCQqrXQkX2OXYHEn6puN7KoMb21DfesO/Be9xU6cLqDyLyvxfFphIYwdqAvRi+7DfQbo5+I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=manuelcanga.dev; spf=pass smtp.mailfrom=php@manuelcanga.dev; dmarc=pass header.from= header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1594549523; s=zoho; d=manuelcanga.dev; i=php@manuelcanga.dev; h=Date:From:To:Cc:Message-ID:In-Reply-To:References:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding; bh=XHRCV/SkpUlnUrwp7YKRMr4hCbFOWpMU0u90AAzPwZ0=; b=ABIk4ypj9Bm54s6EIjKVOookOBosoeMM6Cc3TKvO7UmO6GxGBjdJOhZl2EIoN7iT 4Zd6JGO502z4Z/eij2XtlONWdI86K9YgC+yiSl6RzXS4dZYogYqAJu8U+xUpDYHqMdq UeTbYVzIAo8jCQLmYCDhO4McEggVPhJSwmfhgpFk= Received: from mail.zoho.com by mx.zohomail.com with SMTP id 1594549490754473.28323172517275; Sun, 12 Jul 2020 03:24:50 -0700 (PDT) Date: Sun, 12 Jul 2020 12:24:50 +0200 To: "Benjamin Eberlei" Cc: "Marco Pivetta" , "Nikita Popov" , "PHP internals" Message-ID: <173428d5cae.fd7702bf74344.4165657030995153344@manuelcanga.dev> In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Importance: Medium User-Agent: Zoho Mail X-Mailer: Zoho Mail Subject: Re: [PHP-DEV] [VOTE] Named arguments From: php@manuelcanga.dev (Manuel Canga) Hi, ---- En vie, 10 jul 2020 16:18:40 +0200 Benjamin Eberlei escribi=C3=B3 ---- > On Fri, Jul 10, 2020 at 11:21 AM Marco Pivetta wrot= e: >=20 > > Hi Nikita, > > > > I kept my "NO" stance here, as per discussion in > > https://externals.io/message/110004#110005, where I provided (in my > > opinion) good/safe alternatives to arrays as input parameters. > > >=20 > > The BC implications on this RFC still largely outweigh any advantages = that > > it brings, from my perspective. > > >=20 > Are there alternatives to named parameters? Of course. Are they as simpl= e? > Not really. >=20 > 1. You can use an array, but array values cannot be typed, so you comple= tly > loose typing of the language. > 2. You can use an object with builder pattern, but that requires a lot o= f > code to write, and increases the mental capacity of understanding someth= ing > for developers. > 3. your example of an api to convert named params to a sequence is not > discoverable, you don't know looking or using method A() that it comes w= ith > an additional NamedParamsA() helper. >=20 4. Other option is creating a new function( not yet available in PHP ) lik= e: ``` array_check_scheme( array $array, array $scheme, bool $forced =3D false = ): bool ``` ( name of function can be better ) in order to check types in arrays. Then you could: /** * @param array $args{name: string, surname: string, ?age: int} */ function my_function( array $args ) { $scheme =3D ['name' =3D> 'string', 'surname' =3D> 'string', '?age' =3D> = 'int'); $is_valid =3D array_check_scheme( $args, $scheme ); } my_function( ['name' =3D 'Nikita', 'surname' =3D> 'Popov' ] ); //is_vaild = =3D true my_function( ['name' =3D 'Nikita'] ); //is_vaild =3D false my_function( ['name' =3D 'Nikita'], 'age' =3D> 10 ); //is_vaild =3D false A function like this could be useful in other contexts as well. Regards -- Manuel Canga