Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123260 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 5868B1A009C for ; Fri, 3 May 2024 07:29:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1714721391; bh=pNaTRsiDgUozYFBDmQEfx3MspL8OSKvqqVHt5DnODZg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=jgL85+cjhCd4PhNwmQz7ZXMSY3wy1Z9C01GFoCgK4JGdjyWNHbj/j0q+USqqytCk7 D4S7VbUmO9TNqw3lByN/gNQvXVQDx29p5u8HJhPdF1IPd4bP+JbIyP9HZc5LqiV6IG cIQEAg1tAR2i4fTjePPHHCcHgUnYC8cT8bzaILSwXKQPSzwwMjN26gO47yGPYivakF RTY3xyQB6KAZNaFN0gxAt8FVKZSyoseBINkvySPEwLujGn5nKeabFPi8r5AASXoJBQ NSpvaHtmHGCPaqtzw/OHaeNhliTvV4NV9xtlu7tYrMtMLne975U5RvG4RJGPcOiFho YnbxPXxaJ9LrA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D08361806B1 for ; Fri, 3 May 2024 07:29:50 +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_PASS,FREEMAIL_FROM, HTML_MESSAGE,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-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (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 ; Fri, 3 May 2024 07:29:50 +0000 (UTC) Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-a55bf737cecso1123404466b.0 for ; Fri, 03 May 2024 00:29:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714721344; x=1715326144; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=pNaTRsiDgUozYFBDmQEfx3MspL8OSKvqqVHt5DnODZg=; b=eIz8rUkAsMGhxrkppBpliXOZVpL8piXfptYB/c87eR/zGbGu3O4x8dAYlP07qulrW0 rC/14ck/Y65uGbFtkyK7OmdASHepWMrW//T2tgEJ2/bkBVkMMKE9ieYtLGTZt5eb9vHg zoMb0v+U4/YG1NAKRr7/3iZ1i+yxOyoKH8ItACRHNB2O4MOHCI/c5aHeZF7WqrxvzAOo vpSoLVdRkwLzEDqsKYcjPFREFQbGHJzLH/7PSIU7129unMZ0nfx/eaCnzTkGgFHT0o3D foL6IkUgIMaNgvI4twocb71FxeSSLc3uaNsUp3m+eQX27lhnVUgT/yPp0Dl5LQF/jQuv 5xQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714721344; x=1715326144; h=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=pNaTRsiDgUozYFBDmQEfx3MspL8OSKvqqVHt5DnODZg=; b=m6jtx5zzyRruS4F02+oJ2xboAqcw5wMtUXxMVIp4ik1/3NCG+xPMPgCfLEoOXGpeKK JAOusHLpm0JQRF76ZcbAU6E5MGYg2cZKaax/S5c/bsAjDuMX9J7Phhax+nf0iKXU7mob W+WNqBecIWDH/ZbqNTC4YoM2jcax8i60wv1+d+a1DfirFqn1AgN+qCZ1ISZSX65DbKBL ZOrb/gZj7l+Ean//FgS3XN/QkX1LofJ0teR0uBXsEO0b2Ba0lK/NwGBDwbvEfjQOFKin 0ZobsJEvsonKbW6GzwSVnwJASH860roYMVX5+GAOR1V82xAVJFMSrjVWmvevHVObXoRg Xfew== X-Forwarded-Encrypted: i=1; AJvYcCVsmXBvDgbFBSRhwE+IMch75Ok4vDz6MdH6lG7TvploS0DzgZh10I5O22gDQLG/wCDzAkMk5/EnssPbXpoafGTYI6Y0q6T9Qw== X-Gm-Message-State: AOJu0Yy4L/tIgGGfxLgi6BIPGu4BQOEOrOegJZq9gddQOLb8f7FVjGIY MPa2+IEFjnOaQP46k1r8DjoNi+L8GiiA2FXIREFHBrelE4eu7bW1YG0W26jNmZRtYnaJp34+GJO BD8Q8co88f/fBd7VZKJDPrLtn1hnusA== X-Google-Smtp-Source: AGHT+IEpzESCOQCpso2XyTxq2MYupKLJsgAlmVJq7vPXwJ4YfkF7qC6MkrEr80J7fPWTX/YD5NDAhuqJ7C0tCcxjc08= X-Received: by 2002:a50:d519:0:b0:570:5b71:4859 with SMTP id u25-20020a50d519000000b005705b714859mr860857edi.41.1714721343535; Fri, 03 May 2024 00:29:03 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: <88ea5de8-22ea-4c23-b570-229acd546c10@app.fastmail.com> In-Reply-To: Date: Fri, 3 May 2024 09:28:38 +0200 Message-ID: Subject: Re: [PHP-DEV] Inconsistencies between parameter number and index when reflecting a method/function To: =?UTF-8?Q?Benjamin_Au=C3=9Fenhofer?= Cc: Ollie Read , =?UTF-8?Q?Bj=C3=B6rn_Larsson?= Content-Type: multipart/alternative; boundary="0000000000009202fb061787ac65" From: kjarli@gmail.com (Lynn) --0000000000009202fb061787ac65 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, May 2, 2024 at 10:21=E2=80=AFPM Benjamin Au=C3=9Fenhofer wrote: > > > On Thu, May 2, 2024 at 2:51=E2=80=AFPM Ollie Read wrote= : > >> Hi All, >> >> I've been working on a PR that introduces >> ReflectionFunctionAbstract::getParameter() and >> ReflectionFunctionAbstract::hasParameter(), to fall more inline with the >> other method sets we have, as well as just generally making peoples live= s >> easier. >> >> The PR is here: https://github.com/php/php-src/pull/10431 >> >> These methods accept an integer to retrieve a parameter by its position, >> or a string to retrieve by its name. So far, I have built this so that i= f >> you required the first parameter, it's parameter 0. I treat it this way >> because the only other place where we deal with parameter indexes, is >> ReflectionFunctionAbstract::getParameters() which returns the parameters >> zero-indexed. >> >> The question that is holding this PR back is should these methods be 1 >> indexed, so that the provided position is consistent with the error >> messages, or how a person would typically count, or should they be 0 >> indexed to remain consistent with the existing API. >> > > PHP being a mostly zero indexed language I would say it should be > getParamter(0) to get the parameter #1 (referred to as 1 in error > messages). > >> >> Girgias has asked that I pause the PR until we can have a discussion on >> this mailing list about how to approach it, so I'm looking for feedback = on >> this. >> >> >> --- >> Best Regards, >> *Ollie Read* >> >> The parameter number always confuses me because parameter 4 is actually the 4th, not the 3rd like I'd expect if I look at the indexes when `...$parameters`. Whenever I get an error about parameters I always have to triple check and it costs me extra time to verify the number. I wouldn't mind having this number be consistent with the array indexes instead. I write Lua on a regular basis and everything starts with 1, but it's consistent in the behavior so I never have to think twice. --0000000000009202fb061787ac65 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Thu, May 2, 2024 at 10:21=E2=80=AF= PM Benjamin Au=C3=9Fenhofer <kont= akt@beberlei.de> wrote:


On Thu, May 2, 2024 = at 2:51=E2=80=AFPM Ollie Read <php@ollie.codes> wrote:
Hi All,<= br>

I've been working on a PR that introd= uces ReflectionFunctionAbstract::getParameter() and ReflectionFunctionAbstr= act::hasParameter(), to fall more inline with the other method sets we have= , as well as just generally making peoples lives easier.

=
The PR is here: https://github.com/php/php-src/pull/10431

These methods accept an integer to retrieve a param= eter by its position, or a string to retrieve by its name. So far, I have b= uilt this so that if you required the first parameter, it's parameter 0= . I treat it this way because the only other place where we deal with param= eter indexes, is ReflectionFunctionAbstract::getParameters() which returns = the parameters zero-indexed.

The question that= is holding this PR back is should these methods be 1 indexed, so that the = provided position is consistent with the error messages, or how a person wo= uld typically count, or should they be 0 indexed to remain consistent with = the existing API.

PHP being a mostly zero indexed language I would say it should be getPar= amter(0) to get the parameter #1 (referred to as 1 in error messages).=C2= =A0
<= div>

Girgias has asked that I pause the PR until w= e can have a discussion on this mailing list about how to approach it, so I= 'm looking for feedback on this.


---
Best Regards,
Ollie Read
<= div>

The parameter number always confuses me because parameter 4 is act= ually the 4th, not the 3rd like I'd expect if I look at the indexes whe= n `...$parameters`. Whenever I get an error about parameters I always have = to triple check and it costs me extra time to verify the number. I wouldn&#= 39;t mind having this number be consistent with the array indexes instead. = I write Lua on a regular basis and everything starts with 1, but it's c= onsistent in the behavior so I never have to think twice.=C2=A0
= --0000000000009202fb061787ac65--