Hello!

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)




Atenciosamente,
David Rodrigues

Reply via email to