note 101151 rejected from reflectionparameter.getdefaultvalue by irchtml
| From: | irchtml@php.net | Date: | Tue, 30 Nov 2010 07:27:10 +0000 |
| Subject: | note 101151 rejected from reflectionparameter.getdefaultvalue by irchtml | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-174462@lists.php.net to get a copy of this message | ||
Note Submitter: Pistachio
----
It's not currently possible to obtain the name of a constant defined as a default value for a
parameter.
For example:
<?php
function foo($test, $bar = PHP_OS)
{
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;
}
?>
Will print:
Name: test
Name: bar
Default value: LIN
Rather than:
Name: test
Name: bar
Default value: PHP_OS
If any one has an idea of how to accomplish this, I'd be interested.