Feature Proposal

From: Date: Thu, 14 Jan 2021 17:52:24 +0000
Subject: Feature Proposal
Groups: php.internals 
Request: Send a blank email to internals+get-112881@lists.php.net to get a copy of this message
This is my first foray into PHP internals, so please let me know if I'm doing something wrong. Currently just following the instructions from https://wiki.php.net/rfc/howto. Currently this proposal is only a "concept". I propose we add a "default" keyword that can be passed as an argument into a function/method call. This would allow the calling code to defer to the function signature for the value of a parameter. Traditionally, all optional parameters are placed towards the end of the function parameter list, but as we all know, sometimes this order can be tricky. So if some calling code wants to override a later parameter, it currently needs to pass a value to the earlier optional parameters. A current solution around this is to define all defaults in the body of the function rather than in the signature. [image: Screen-Shot-2021-01-14-at-11.45.09-AM.jpg] However, this adds some extra boilerplate, and we can't use default parameters as they were really intended. My proposal is to add a new default keyword to be passed as an argument. [image: Screen-Shot-2021-01-14-at-11.44.57-AM.jpg] The first call of the function here is how we currently have to do things. We have to explicitly pass true in as the second parameter. However, in the second call, we now use the new default keyword, which will defer to the function signature for the default value of $param2. Thanks all, looking forward to some feedback! -- Andrew M. Brown

« previous php.internals (#112881) next »