On Thu, May 2, 2024 at 10:21 PM Benjamin Außenhofer <kont...@beberlei.de> wrote:
> > > On Thu, May 2, 2024 at 2:51 PM 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. >> > > 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.