Is this legal?
<?php
function ftw($foo = 'pwnage', $nub = MENU_DEFAULT_VALUE, $odp = ODP_DEFAULT_VALUE) {
//lots_of_awesome_code
}
?>
where MENU_DEFAULT_VALUE and ODP_DEFAULT_VALUE are constants defined previously in the file.
Is this legal?
<?php
function ftw($foo = 'pwnage', $nub = MENU_DEFAULT_VALUE, $odp = ODP_DEFAULT_VALUE) {
//lots_of_awesome_code
}
?>
where MENU_DEFAULT_VALUE and ODP_DEFAULT_VALUE are constants defined previously in the file.
Yes, that is legal.
From the manual:
The default value must be a constant expression, not (for example) a variable, a class member or a function call.
Constants fit that bill perfectly.
static but just via self, when setting defaults for a class method argument?static is subject to late static bindings, making it inconstant.why don't you try ?
Still, just in case you can test right now, the following code :
define('MENU_DEFAULT_VALUE', 10);
define('ODP_DEFAULT_VALUE', 'hello');
function ftw($foo = 'pwnage', $nub = MENU_DEFAULT_VALUE, $odp = ODP_DEFAULT_VALUE) {
var_dump($foo);
var_dump($nub);
var_dump($odp);
}
ftw();
gives this output :
string 'pwnage' (length=6)
int 10
string 'hello' (length=5)
So I'd say that, yes, it is valid :-)
static, but just using self; this myMethod($arg1 = static::MY_CONST) won't work. Do you know any valid explanation for this different behaviour?