Re: Inconsistencies between parameter number and index when reflecting a method/function
| From: | Robert Landers | Date: | Fri, 03 May 2024 06:46:38 +0000 |
| Subject: | Re: Inconsistencies between parameter number and index when reflecting a method/function | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-123258@lists.php.net to get a copy of this message | ||
On Fri, May 3, 2024 at 4:01 AM Gina P. Banyard <internals@gpb.moe> wrote:
>
> On Thursday, 2 May 2024 at 21:33, Derick Rethans <derick@php.net> wrote:
>
> > On 2 May 2024 13:48:36 BST, Ollie Read php@ollie.codes wrote:
> >
> > > 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 if 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.
> >
> >
> > 0-indexed, as that's what PHP does everywhere else.
> >
> > cheers
> > Derick
>
> Well not really, if you have an error (TypeError or ValueError) which indicate what parameter
> is the problem, it will be 1-indexed.
>
> Which, for me, makes it more logical to have it 1-indexed.
> If the ReflectionFunctionAbstract::getParameters() API did not exist, this is what I would have
> pushed for.
>
> Moreover, PHP already has a 1-indexed and 0-indexed discrepancy with the ob_get_level() and
> ob_get_status() functions.
>
> In the end, I don't really care what we choose, but this just needed clarification from
> internals on how to proceed.
>
> Best regards,
>
> Gina P. Banyard
There's no discrepancy with ob_get_level and ob_get_status.
ob_get_level starts at 0 (no ob) and ob_get_status is count(0) with
no_ob.
count(ob_get_status(true)) === ob_get_level()
Robert Landers
Software Engineer
Utrecht NL