Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110965 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 50670 invoked from network); 12 Jul 2020 15:14:26 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 12 Jul 2020 15:14:26 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5C95F1804C6 for ; Sun, 12 Jul 2020 07:06:23 -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 07:06:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594562778; cv=none; d=zohomail.com; s=zohoarc; b=X/P6HYZ+tUI9ArOq8k5n5Z87DdAT1oR5kZyZecGKEaqhRe6AORE5NB/RYWhf70ptemdiPNFQO1qCJthfuOJIt9s5OqGkTVxQEyvYipRDuhd93BKbB/VfIf4pb9OvVydEln2KanuWnGuFZxLISCvEchOTawY+BlR65aqWazKL3U8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594562778; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=XA/fEGBiKDgRagRQHCJ3Ot5AUWTUZsKEVp8KLTHh3xI=; b=kMrcVI8cdQ6rO/cpIvgIJUXF1wS7B5TYkwt2eem/ioF1dOofOTqtiEA9YFsAvYNueZhtqk2S6mJK+awDXFJSMQvwviHK1CM1chBEyTW50G8O67ev9i5IaCRfqcnni0LcC+53uikK0YbsrcEV1/IdYGio3xOC3Y1gGAlfZGq4bcg= 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=1594562778; 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=XA/fEGBiKDgRagRQHCJ3Ot5AUWTUZsKEVp8KLTHh3xI=; b=SoXL0IWvavq/TUsHBdQWKpv5l/LmORyQk6zyMBhAk/ABXyEz49Ax5aKdCXgF66W/ bhTf6WzhNY8JAydP00HTY4zwT9cXQtl1geObnplNfzsePkteNpcIsE/a6Fg2aYjNRZe 6twULuAoPh2QYfZL6vvtTr1Upn4RPUrUGMNry1Fs= Received: from mail.zoho.com by mx.zohomail.com with SMTP id 1594562745149721.901624502625; Sun, 12 Jul 2020 07:05:45 -0700 (PDT) Date: Sun, 12 Jul 2020 16:05:45 +0200 To: "Rowan Tommins" Cc: "internals" Message-ID: <17343580071.1058bc47b82584.7264195986508190405@manuelcanga.dev> In-Reply-To: <156CE5DB-BD37-4EA3-A1B3-5E88DA5E73BA@gmail.com> References: <173428d5cae.fd7702bf74344.4165657030995153344@manuelcanga.dev> <156CE5DB-BD37-4EA3-A1B3-5E88DA5E73BA@gmail.com> 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, Rowan, ---- En dom, 12 jul 2020 14:19:08 +0200 Rowan Tommins escribi=C3=B3 ---- > The problem with this, whether built in or not, is that you have to expr= ess everything with strings rather than keywords. That means, for instance,= that invalid values in the definitions themselves will only error at run-t= ime. The definitions also tend to get verbose pretty quickly. >=20 > To make it concise and checked at compile-time, you need it to be a cons= truct that pairs identifiers to types without first representing them as st= rings, e.g. to write `?string $foo =3D 'hello'` rather than `'foo' =3D> ['t= ype'=3D>'string', 'nullable'=3D>true, 'default'=3D>'hello']`. It turns out = we already have a construct for doing that: function signatures. >=20 > If the input is an actual array or object coming from "outside", you're = probably going to want a more extensible validation system anyway. Those ar= e really hard to design, and probably best left to userland where people ca= n choose the tradeoffs they prefer. >=20 > Regards, >=20 I see.=20 However, with named arguments you also have to implement changes in parser = in order to can recognize named arguments. You also have to change behavior= about default parameters. I don't know if this change affect to performanc= e, maybe do.=20 By the other hand, editor like PHPStorm has "Inlay Hints":=20 https://www.jetbrains.com/help/rider/Inline_Parameter_Name_Hints.html With a function which checks scheme, you also could use in other contexts, = like forms: ``` $scheme =3D ['name' =3D> 'string', 'surname' =3D> 'string', '?age' =3D> 'in= t'); $is_valid =3D array_check_scheme( $_POST, $scheme );=20 ``` You can use it even with JSON: ``` $request =3D json_decode( $request_json, true ); $scheme =3D ['name' =3D> 'string', 'surname' =3D> 'string', '?age' =3D> 'in= t'); $is_valid =3D array_check_scheme( $request, $scheme );=20 ``` > e.g. to write `?string $foo =3D 'hello'` rather than `'foo' =3D> ['type'= =3D>'string', 'nullable'=3D>true, 'default'=3D>'hello']` Maybe you don't need checked at compile-time. is it slow?, securely, but y= ou don't use in everywhere. > you're probably going to want a more extensible validation system anyway. Maybe, in that case, userland libraries have a starting point. With XML par= sing is the same. PHP provides basic functionality=20 and userland provide advanced. Regards -- Manuel Canga