Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123256 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 39CDD1A009C for ; Thu, 2 May 2024 23:11:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1714691546; bh=TAHcsNRjSu7cwO5oFq64yfQjEg/tvpN8/rzhr5/i2CU=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=bWaKbv2If3h0cW7g3HJYky4/2lMH41DWEFpgT+Jfprpimiwvr0r9JI+pZeKZBElv+ 05rFD4EPelYCyGFPk0GJZOASWpK4CGjgeUJ8jNhJtV0j+1u1QXTD2xdsFaSkurjirx zbNvHEjoNYSrzYxdNHzcIqMHC1LOq4KfGb7F9TI0WyVHHe6JnhlZ9P6iDW0QKZ887x QR8ADQTcEczQDZTI3UDyT2V6b+/Xc0eSDqVBRWLDPMdb+o9BihVrprAuE5TUgOkzVo bKvpuCrDAQbjv/LwWmhxK/XPg7VjjMuJmTEjpKj2sspcCznedH6S3loksFsFJSZp/4 qKIZDYceRCXrg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4D6DB18005D for ; Thu, 2 May 2024 23:12:25 +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-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.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, 2 May 2024 23:12:24 +0000 (UTC) Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-51f300b318cso1448347e87.3 for ; Thu, 02 May 2024 16:11:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714691498; x=1715296298; 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=TAHcsNRjSu7cwO5oFq64yfQjEg/tvpN8/rzhr5/i2CU=; b=KTTauYDziBzqgWqh8g69ZNYwAwhU5pcbVLIJUR7yQKdDP1GY5l0DN4iUwDROLaPuqR SlEYi76RKH+IcQ1BoGJvlnxiT4ZPPw7WO3XQZ5dKMnfhQI3WI5wurDVABODaCYNM+sDF 2praHdvjD6ni+0zsUC1xmI4afMvPBp2j1IHmlzxcrfnQvAuvy2OBS2bJo4bBoFxQoWBU dRuG97P3ETTH6HdPhaVUcuzbPCfejuQ0BdNW9txZSunPUSZ/8hStxc6bJMePtQ/WxmCK AisozZsvI0em+e+/9AAizMHxeRG83fvfzGxq4YgR2fZSHvp4zvmk5EiAVNQM6gFeFyaw EEuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714691498; x=1715296298; 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=TAHcsNRjSu7cwO5oFq64yfQjEg/tvpN8/rzhr5/i2CU=; b=jMNAnu9mHqWJMasgksczI3IXiYySIg4CdFWPtHdLtY9TDe43Zk+zafybGWi3k+9hef F9v0/OJZq4zFltoI6hw+T9fKMmfi9JAQ3GckcvH6JXYJDlAMVqViJ5oTnWhnXI7ufuds H23IBIlChvB/V/VBrWz15cemGcS5KSsl2NtopC9j6hIqFmzXiD1ceFOopFZsvyY98g75 ybnZwgm2NkLwOyQMuU0belaLW7VPxv3WeXKpY00SUJ26XooeWCL2a4PCKsH8nRPgfbN3 DecxjXUvLrFa70DQXdlOnHmT9n28cMNx3ADiRywQER4E5XlsvjgpdwJPfOgXmvlHwopV eKbQ== X-Forwarded-Encrypted: i=1; AJvYcCVzTvRRaQAlCz8vy4iKtxbXJDwwLjQX6qByNA1ANwhZjWFyvcz4A+UvTGvfgkfhpYq9iLC4g+BjQijP4p9k1zbJmOI8ceBwlw== X-Gm-Message-State: AOJu0Yym2wVYAnbd3qsGMMzbyp3OWFDodvmWzDCiGrVbZbxm2514rqEw /vOdCNVRiCJfbuC7z3JHTjd/ePNYlDpxdcsJic/mdfWxu21pAPwpIvD2+At+KkcghMQM4lpM4gi YvKp1BhwtTl/gBM9Zb2O/bJyXAdc= X-Google-Smtp-Source: AGHT+IEy7AMGGzxPG/RL4KgcrqjHvKFqwdHLlHiTH2/1+e9Yv1xxuch63fQJ/xsHJF4Vra6WiECMHb2Q+vpdGwmjkcs= X-Received: by 2002:a05:6512:10cc:b0:51d:8882:cd69 with SMTP id k12-20020a05651210cc00b0051d8882cd69mr929858lfg.53.1714691497727; Thu, 02 May 2024 16:11:37 -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 01:11:24 +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="0000000000009f20a0061780b9fd" From: landers.robert@gmail.com (Robert Landers) --0000000000009f20a0061780b9fd Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, May 2, 2024 at 10:22=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* >> >> Parameter zero is the first parameter. Both are correct, we access memory from the start (0), but as humans, we count total items. You never say I have zero goats and really mean that you have one goat. However, if you wanted to start at the beginning of a line of goats, you'd start at position zero to get the first goat. Robert Landers Software Engineer Utrecht NL --0000000000009f20a0061780b9fd Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Thu, May 2, 2024 at 10:22=E2= =80=AFPM Benjamin Au=C3=9Fenhofer <kontakt@beberlei.de> wrote:


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

I've been working on a PR that introduces ReflectionFunctionAbstract= ::getParameter() and ReflectionFunctionAbstract::hasParameter(), to fall mo= re inline with the other method sets we have, as well as just generally mak= ing peoples lives easier.


These m= ethods accept an integer to retrieve a parameter by its position, or a stri= ng to retrieve by its name. So far, I have built this so that if you requir= ed the first parameter, it's parameter 0. I treat it this way because t= he only other place where we deal with parameter indexes, is ReflectionFunc= tionAbstract::getParameters() which returns the parameters zero-indexed.

The question that is holding this PR back is sho= uld 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 inde= xed language I would say it should be getParamter(0) to get the parameter #= 1 (referred to as 1 in error messages).=C2=A0

Gir= gias has asked that I pause the PR until we can have a discussion on this m= ailing list about how to approach it, so I'm looking for feedback on th= is.


---
Best Regards,
Ollie Read


Parameter zero is the first paramet= er. Both are correct, we access memory from the start (0), but= as humans, we count total items. You never say I have zero goats and reall= y mean that you have one goat. However, if you wanted to start at the begin= ning of a line of goats, you'd start at position zero to get the first = goat.

Robert Landers
Software E= ngineer
Utrecht NL

--0000000000009f20a0061780b9fd--