Request to create a RFC for const args

php.internals

Sam McDonald

3 years ago
Hello php internals team, I would like to put forward an RFC for a new feature. I am a long time user, but have never participated as yet to the RFC. This is my first step to gather reaction/feedback from the team. I would be happy to implement the feature and post a PR or have someone from the team implement this. The feature I want to put forward is "const function arguments" (same for methods) This feature is available in cpp, and I believe would be a benefit to the php community. My RFC would fully detail and clarify what this is and how it works. This feature allows the user to specify "const" on a function arg, so that the argument while in a function can not be reassigned. The following example would throw an exception at compile/runtime. ``` public function foo(const int $bar) { $bar =3D "buz"; } ``` The same for complex types such as arrays and classes, if a 'const' arg is provided, while in the function it can not be reassigned. Please let me know if this is something the team is interested in and if I should proceed. Kind regards. Sam McDonald. Sent from Outlook for Android<https://aka.ms/AAb9ysg>

Olle Härstedt

3 years ago
2023-06-19 9:56 GMT+02:00, Sam McDonald <s.mcdonald@outlook.com.au>:
> Hello php internals team, > I would like to put forward an RFC for a new feature. I am a long time user, > but have never participated as yet to the RFC. > > This is my first step to gather reaction/feedback from the team. > > I would be happy to implement the feature and post a PR or have someone from > the team implement this. > > The feature I want to put forward is "const function arguments" (same for > methods) > > This feature is available in cpp, and I believe would be a benefit to the > php community. > > My RFC would fully detail and clarify what this is and how it works. > > This feature allows the user to specify "const" on a function arg, so that > the argument while in a function can not be reassigned. > > The following example would throw an exception at compile/runtime. > > ``` > public function foo(const int $bar) > { > $bar =3D "buz"; > } > ```
Isn't this similar to my own idea of readonly function arguments? https://externals.io/message/120203#120210 Perhaps more limited in scope? Olle

Sam McDonald

3 years ago
He6 Olle, Yes more so the former, not the latter in your example. If there is already an rfc in place then that is fantastic. Regards SAM Sent from Outlook for Android<https://aka.ms/AAb9ysg> ________________________________ From: Olle Härstedt <olleharstedt@gmail.com> Sent: Monday, June 19, 2023 7:47:49 PM To: Sam McDonald <s.mcdonald@outlook.com.au> Cc: internals@lists.php.net <internals@lists.php.net> Subject: Re: [PHP-DEV] Request to create a RFC for const args 2023-06-19 9:56 GMT+02:00, Sam McDonald <s.mcdonald@outlook.com.au>:
> Hello php internals team, > I would like to put forward an RFC for a new feature. I am a long time user, > but have never participated as yet to the RFC. > > This is my first step to gather reaction/feedback from the team. > > I would be happy to implement the feature and post a PR or have someone from > the team implement this. > > The feature I want to put forward is "const function arguments" (same for > methods) > > This feature is available in cpp, and I believe would be a benefit to the > php community. > > My RFC would fully detail and clarify what this is and how it works. > > This feature allows the user to specify "const" on a function arg, so that > the argument while in a function can not be reassigned. > > The following example would throw an exception at compile/runtime. > > ``` > public function foo(const int $bar) > { > $bar =3D "buz"; > } > ```
Isn't this similar to my own idea of readonly function arguments? https://externals.io/message/120203#120210 Perhaps more limited in scope? Olle

Olle Härstedt

3 years ago
2023-06-19 12:59 GMT+02:00, Sam McDonald <s.mcdonald@outlook.com.au>:
> He6 Olle, > Yes more so the former, not the latter in your example. > If there is already an rfc in place then that is fantastic. > Regards > SAM
There's no RFC, just me mailing out the idea when I had it. :) Go wild. Olle

Ilija Tovilo

3 years ago
Hi Sam!
> Hello php internals team, > I would like to put forward an RFC for a new feature. I am a long time user, but have never participated as yet to the RFC.
Sorry for the late reply. Thanks for your suggestion! If you'd like RFC karma, we'll need to know your username on the wiki. Ilija