i know how to get function parameters.
I am using of course ReflectionMethod to get function parameters but currently i am not able to get default value of those parameter.
this is my code where function is defined
class A{
public function fn($para1,$para2="not required"){
//some kind of stuff
}
}
code for getting function parameter
$meth = new ReflectionMethod("A","fn");
foreach ($meth->getParameters() as $param) {
//some kind of stuff
}
now please tell how do i get default value of function parameter
From the docs:
<?php
function foo($test, $bar = 'baz')
{
echo $test . $bar;
}
$function = new ReflectionFunction('foo');
foreach ($function->getParameters() as $param) {
echo 'Name: ' . $param->getName() . PHP_EOL;
if ($param->isOptional()) {
echo 'Default value: ' . $param->getDefaultValue() . PHP_EOL;
}
echo PHP_EOL;
}
?>
http://www.php.net/manual/en/reflectionparameter.getdefaultvalue.php
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments