Inconsistencies between parameter number and index when reflecting a method/function
| From: | Ollie Read | Date: | Thu, 02 May 2024 12:48:36 +0000 |
| Subject: | Inconsistencies between parameter number and index when reflecting a method/function | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-123251@lists.php.net to get a copy of this message | ||
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.
---
Best Regards,
*Ollie Read*