Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122929 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 2EAD31A009C for ; Thu, 4 Apr 2024 13:03:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712235839; bh=kBq+JW3y1Wauk14yIu9dW+VNLudHwXKFQIr3aIidB7Q=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=TIEHrThc6woz8LiQwT+NMYykmHkNWHbYb00KkkSns5yr2peSyVmQmgUdR71ekBp2e enCaMp/zFYMbJyGnWW8dvwcFLfa5dL8PUbV7+8zsw6F5grv4TlJW66x5yUmzPAFYGB GvMMNWfMJom9VNuQrSzLXP5fsj4KIZkJLL/Y7rwjfYL1dZn4CLBiKDbQDaFLYLUsba f87HMacDwMvzzrLZB6voGvroLBjvUTCNnxo7xaNxk1q3idayaujEhy8WrIqbjjFaVg JnVdW/AJE8QizcICtgw40UtIu55tRsorQ2SnhDqVATX3VTNNhlbz7HRRNkt0Xox/Aw U1CFLv/Eq1PaA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 601B718006E for ; Thu, 4 Apr 2024 13:03:58 +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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,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 mail-io1-f53.google.com (mail-io1-f53.google.com [209.85.166.53]) (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 13:03:57 +0000 (UTC) Received: by mail-io1-f53.google.com with SMTP id ca18e2360f4ac-7cc0b35b75bso34108839f.3 for ; Thu, 04 Apr 2024 06:03:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=itafroma.com; s=google; t=1712235808; x=1712840608; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=CJHjy8tdIVAdih5pS28s4h2nQ1vqiSfXjPptT/ytE8U=; b=fxDf/c8UzS2BkfQHNlqBLA7FtNt1MPEycunRxV+xAEeaCdMffYBmaDU2cG4RUTmSMY MvInXuBZkamgwmfPBZZxlrlHVGocqUxLpoWldikqUQEkPTbeXoh1RU7YLkciTj6kWXPW juh69QatrND8pf0ESEi40zj6KZi6QaQZEneEU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712235808; x=1712840608; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CJHjy8tdIVAdih5pS28s4h2nQ1vqiSfXjPptT/ytE8U=; b=bgpTF6GEX31nAK2BRuu8PsPGqOX3lRRIdBv8L8leUMsR4h8DZm1xcMgKTpli3HZeT0 b/WE1y4L3C83plCaT1spBNU7YHy+sm+KXhLS0jIiR5ky3Wibsc0lKX7i+yP3wVy2bwsw etcGUMiCZ4rRr9NuE1KhZcYCL7ra5f/mdIJhoj+FSf49XYfSqnxuFxNlTPtrAif4aoQI zSK+TrOXx4W2GwGqQZOId0uj4zaTcy8emDZq0Yo1iqZu1PGnuXFOtZxRabFGjfimNAQ3 U9JOX4WVnwWRImoGqNCHHWdUlLX1jXs69vSAbHCydNs3hxUW2jpdNNr1NYCDZP6J1418 xq4A== X-Gm-Message-State: AOJu0YxWWNO6KnUIDJh27pHfwFTcAnQsq2TkSupslYyDPk75K5DXsBv4 ZGHLcmXls7Ua8xs/nAFdbj47FHf1fmhjX3CIAlgNh/N4OOc/AIVqgzvs5HpjcDcowhikSsX+JBD GPGo6qgFYh0AdcEjMEdfyPhb2yAfGmkCnqi+DvxRX1lHwRiRu5w== X-Google-Smtp-Source: AGHT+IFoNlg2cbfRFZoEeqZ8tJOrJ7DenvBOJG4kQFYvGBmb91oK3IfL7rXZRRDd61YEWA7KjtDn9NBkVpXc+DQaP6o= X-Received: by 2002:a05:6e02:3d03:b0:369:f65d:32b8 with SMTP id db3-20020a056e023d0300b00369f65d32b8mr2800873ilb.26.1712235807834; Thu, 04 Apr 2024 06:03:27 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: <6299b649-c19b-4172-9632-2ef0a55d256d@uzy.me> In-Reply-To: <6299b649-c19b-4172-9632-2ef0a55d256d@uzy.me> Date: Thu, 4 Apr 2024 06:03:17 -0700 Message-ID: Subject: Re: [PHP-DEV] RFC idea: using the void type to control maximum arity of user-defined functions To: Pablo Rauzy Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: mark@itafroma.com (Mark Trapp) On Thu, Apr 4, 2024 at 5:43=E2=80=AFAM Pablo Rauzy wrote: > > Hello all, > > First, I'm new here, so let me start by warmly thanking everyone > involved in PHP development. I've started programming 22 years using it > as my first programming language, and still enjoy using it a lot :). > > I've read the rfc:howto and the first step is to get feedback from this > mailing list about the intended proposal, so here is a short description > of what I have in mind: > > Currently PHP does not warn when user-defined functions are called with > too many arguments. Changing this could break a lot of existing code, > but it would also be a very good verification to catch potential bugs. > > I have an idea allowing this feature without breaking any existing code: > using the void keyword in a function arguments list to strictly limit > the number of arguments a user-defined function can receive, stopping it > on the void, which could only be used once and in the last position. > > Currently, void is a return-only type so it isn't used in arguments list > in existing code, so I believe the new behavior would only concern newly > written code that explicitly wants to take advantage of this feature. > > A few examples using functions (the same would apply to class methods, > callbacks, closures, etc.) : > > function foo (void) {} > foo(42); // warning: foo() expects exactly 0 arguments, 1 given > > function bar ($a, $b, void) {} > bar(1, 2, 3); // warning: bar() expects exactly 2 arguments, 3 given > > function baz ($a, $b=3Dnull, void) {} > baz(1, 2, 3); // warning: baz() expects at most 2 arguments, 3 given > > I have no knowledge of the PHP internals: would that be feasible without > breaking things? And, as importantly, would it be a welcome change? > > Cheers, > > -- > Pablo Hi Pablo, 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 sy= ntax. - Mark