Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122934 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 72FA41A009C for ; Thu, 4 Apr 2024 14:36:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712241433; bh=cmzxTdF0mLlUcToDBFHQUVNDj0WkV0RZMLfuOE3f0U0=; h=Date:Subject:To:References:From:In-Reply-To:From; b=mPoLcP69FbzlPT5WQGc0x1OI7mnO440EtR+KAdEHfP8gNCxBLG3n1a9X49lR2Pue5 r3l56mLOM2iCIYZ4BS31ni1PYceVwiCJRAHPkiJYFsY/wMZTXK1+ljOgy0NooGutfK xDscbEBWYWyD6kMcWWn7eB/4oE5gcQUht2Nqr8wxulwnckiTeY1krlKC/zesDf1QPi 2PRWlhBgztJefADNilxw5xl8f6Lrg+YThaoN7n6T4/nqYNdEOf7HuT35LKvQkpRb20 R45hD0FHa3re9lcaoK1fLTDZV3gj0Dq3wFJyiQUxR3PH/ejbk9WmCxDJ1v7rdnZx/T n0TXBtnf0k8gA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D4FC718005B for ; Thu, 4 Apr 2024 14:37:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from smtp-190f.mail.infomaniak.ch (smtp-190f.mail.infomaniak.ch [185.125.25.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 4 Apr 2024 14:37:11 +0000 (UTC) Received: from smtp-3-0001.mail.infomaniak.ch (smtp-3-0001.mail.infomaniak.ch [10.4.36.108]) by smtp-4-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4V9PMD5nqhzb4q for ; Thu, 4 Apr 2024 16:36:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=uzy.me; s=20230717; t=1712241400; bh=cmzxTdF0mLlUcToDBFHQUVNDj0WkV0RZMLfuOE3f0U0=; h=Date:Subject:To:References:From:In-Reply-To:From; b=EKxZyEfVM87ZxzKjBim31NHqGhxOEtHQlDkKXewJar5vZ+F9kkPnIsUCQ601P48+l M3L/CPRBqNUAYqbKxa/7sKz8rdx1MFhhgNniyHBYd4X/Sos6kyXJkI/Y/ixFcgY9PE dHT5daJ8XFoZzSgeur+Crq6ShqZlmd1u0wQhtpb9oJ9jQ/dpM/BYA8fYNroHiB0yQR JdBhmIiChuome2Xr49/iC/bo0xNiDNKQHiN7BBdJ42XC5pV4D7xS6QDKokM6wOOBO+ KU0+EMvsYqQG6zo0NkITqMYhFcxXFkEPKBKUnLtqP1BEzq2w7olb7y12Ykg8ZTahs8 L4iNVePFndr1A== Received: from unknown by smtp-3-0001.mail.infomaniak.ch (Postfix) with ESMTPA id 4V9PMD2QdZzC2c for ; Thu, 4 Apr 2024 16:36:40 +0200 (CEST) Content-Type: multipart/alternative; boundary="------------j0qF9KUWiRmaIjbfaSCLLUfR" Message-ID: <8f71d807-78e6-49f6-acc7-b1fc09d815ba@uzy.me> Date: Thu, 4 Apr 2024 16:36:39 +0200 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] RFC idea: using the void type to control maximum arity of user-defined functions To: internals@lists.php.net References: <6299b649-c19b-4172-9632-2ef0a55d256d@uzy.me> <7B32AF65-CA40-40F5-BA59-CB5180EC4D7F@gmail.com> Content-Language: fr In-Reply-To: <7B32AF65-CA40-40F5-BA59-CB5180EC4D7F@gmail.com> X-Infomaniak-Routing: alpha From: r@uzy.me (Pablo Rauzy) This is a multi-part message in MIME format. --------------j0qF9KUWiRmaIjbfaSCLLUfR Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Le 04/04/2024 à 16:29, Claude Pache a écrit : > Le 4 avr. 2024 à 15:03, Mark Trapp a écrit : >> On Thu, Apr 4, 2024 at 5:43 AM Pablo Rauzy wrote: >> >> I like this concept, but instead of introducing a new syntax, have you >> considered leveraging attributes in the same way that PHP 8.3 >> introduced #[Override]? >> >> #[Nonvariadic] >> function foo () {} >> foo(42); // warning: foo() expects exactly 0 arguments, 1 given >> >> I think the intent would be clearer and it would avoid introducing a new syntax. >> > Indeed, except that I think it should be better to have *by default* the same behaviour between built-in functions and user-defined functions: > > ```php > function foo() { } > > foo(42); > // in PHP 8.x: Deprecated: foo() expects expects exactly 0 arguments, 1 given > // in PHP 9: Fatal error: foo() expects expects exactly 0 arguments, 1 given > ``` > > and, in case you want a variadic function: > > ```php > #[Variadic] > function foo() { } > ``` > > Alternatively, we don’t really need to introduce a new attribute, because one can just write: > > ```php > function foo(...$args) { } > ``` > > > —Claude Hello Claude, I strongly agree in theory, but this could break existing code, and moreover such a proposal was already rejected: https://wiki.php.net/rfc/strict_argcount Regards, -- Pablo --------------j0qF9KUWiRmaIjbfaSCLLUfR Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
Le 04/04/2024 à 16:29, Claude Pache a écrit :
Le 4 avr. 2024 à 15:03, Mark Trapp <mark@itafroma.com> a écrit :
On Thu, Apr 4, 2024 at 5:43 AM Pablo Rauzy <r@uzy.me> wrote:

I like this concept, but instead of introducing a new syntax, have you
considered leveraging attributes in the same way that PHP 8.3
introduced #[Override]?

#[Nonvariadic]
function foo () {}
foo(42); // warning: foo() expects exactly 0 arguments, 1 given

I think the intent would be clearer and it would avoid introducing a new syntax.

Indeed, except that I think it should be better to have *by default* the same behaviour between built-in functions and user-defined functions:

```php
function foo() { }

foo(42);
// in PHP 8.x: Deprecated: foo() expects expects exactly 0 arguments, 1 given
// in PHP 9: Fatal error: foo() expects expects exactly 0 arguments, 1 given
```

and, in case you want a variadic function:

```php
#[Variadic]
function foo() { }
```

Alternatively, we don’t really need to introduce a new attribute, because one can just write:

```php
function foo(...$args) { }
```


—Claude

Hello Claude,

I strongly agree in theory, but this could break existing code, and moreover such a proposal was already rejected:
https://wiki.php.net/rfc/strict_argcount

Regards,

-- 
Pablo
--------------j0qF9KUWiRmaIjbfaSCLLUfR--