On Thursday, 2 May 2024 at 13:48, Ollie Read <php@ollie.codes> 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 lives 
> 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 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.
>
> 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

I am not sure why I had not thought about checking this earlier, but 
ReflectionParameter has a getPosition method [1], where the first parameter of 
a function/method is 0.
So the _best_ argument for having it 0 indexed based is to be consistent with 
the existing semantics.

So I am fine with having it 0 indexed.

Best regards,
Gina P. Banyard

[1] https://www.php.net/manual/en/reflectionparameter.getposition.php

>

Reply via email to