On 14.03.2020 at 16:27, David Rodrigues wrote: > I would like to propose the idea of having a keyword that can be used to > use the default value of a parameter, without necessarily having to know > it. Since PHP is not a strong typing language, the default values they use > are quite mixed, and it is difficult to predict each without knowing the > documentation (if you have documented it) or using IDE support. > > public function __construct($data = []); > public function __construct($data = null); > > I always prefer to use null as the default value to optional parameter, and > then define the value transformation in case it is null. But a lot of > third-party code defines how they want the default value. > > String: null or '' > Array: null or [] > Integer: null or 0 > Boolean: null, true or false > > In addition to other values that can actually be used as defaults in a more > specific way. > > public function test(int $pi = M_PI, int $a = null, int $b = 0) > > My suggestion would be to use the keyword "default" in the context of the > argument. To avoid confusion, another keyword could be created, but I don't > see why they confuse "default" as an argument and "default" for switch. > > test(default, 2) === test(M_PI, 2, 0)
FWIW, this has been proposed as RFC[1] quite a while ago, but has been declined. [1] <https://wiki.php.net/rfc/skipparams> -- Christoph M. Becker -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php