2008/5/22 Stan Vassilev | FM sv_forums@fmethod.com:
Hi,
Actually PHP ignores default values on parameters followed by required ones.
You can't fetch the default value even via Reflection.
This is easily detected at compile time so I wonder why the compiler doesn't
warn.Regards,
Stan Vassilev
I'm not sure this is what you mean, but I use the following function
in my debugging logic.
<?php
function getArgs($s_Function, array $a_PassedParams = array()) {
$a_Arguments = array();
if ('' !== $s_Function) {
$rf_This = new ReflectionFunction($s_Function);
foreach($rf_This->getParameters() as $i_Param => $rp_Param) {
$a_Arguments[$rp_Param->getName()] = $i_Param <
count($a_PassedParams) ? $a_PassedParams[$i_Param] :
$rp_Param->getDefaultValue() . ' (Default)';
}
}
return $a_Arguments;
}
function foo($required, $optional = 'snafu', $also_optional = 'sins') {
print_r(getArgss(FUNCTION, func_get_args()
));
}
foo('fred');
foo('bob', 'jim');
outputs ...
Array
(
[required] => fred
[optional] => snafu (Default)
[also_optional] => sins (Default)
)
Array
(
[required] => bob
[optional] => jim
[also_optional] => sins (Default)
)
--
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"
Hi,
Please notice that I said "followed by required ones".
function foo($a = null, $b) {}
The above definition is allowed and the compiler won't complain, but
actually that "= null" is completely lost, including in Reflection.
Regards,
Stan Vassilev
2008/5/22 Stan Vassilev | FM sv_forums@fmethod.com:
Hi,
Actually PHP ignores default values on parameters followed by required
ones.
You can't fetch the default value even via Reflection.
This is easily detected at compile time so I wonder why the compiler
doesn't
warn.Regards,
Stan VassilevI'm not sure this is what you mean, but I use the following function
in my debugging logic.<?php
function getArgs($s_Function, array $a_PassedParams = array()) {
$a_Arguments = array();
if ('' !== $s_Function) {
$rf_This = new ReflectionFunction($s_Function);
foreach($rf_This->getParameters() as $i_Param => $rp_Param) {
$a_Arguments[$rp_Param->getName()] = $i_Param <
count($a_PassedParams) ? $a_PassedParams[$i_Param] :
$rp_Param->getDefaultValue() . ' (Default)';
}
}
return $a_Arguments;
}function foo($required, $optional = 'snafu', $also_optional = 'sins') {
print_r(getArgss(FUNCTION,func_get_args()
));
}foo('fred');
foo('bob', 'jim');outputs ...
Array
(
[required] => fred
[optional] => snafu (Default)
[also_optional] => sins (Default)
)
Array
(
[required] => bob
[optional] => jim
[also_optional] => sins (Default)
)--
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"
Hi,
Am Donnerstag, den 22.05.2008, 18:23 +0300 schrieb Stan Vassilev | FM:
[...]
function foo($a = null, $b) {}
Isn't that a typical case for throwing an E_STRICT
warning or is is not
possible to check that efficiently in the engine?
cu, Lars