Just posting some example code for anyone wanting to mess around with this stuff:
<?php
class Say
{
private $what_to_say;
public function __construct($no_default, $word = "Hello World", $options = array('a', 'b'))
{
$this->what_to_say = $word;
}
public function speak()
{
echo $this->what_to_say;
}
}
$class = new ReflectionClass('Say');
$constructor = $class->getConstructor();
echo $constructor;
$parameters = $constructor->getParameters();
var_export($parameters);
$nl = "\n";
echo "$nl\tParameters$nl";
foreach($parameters as $param)
{
echo "****** $" . $param->name . " ******$nl";
echo "Nullable:\t\t" . $param->allowsNull() . $nl
."Default Value:\t\t";
echo ($param->isDefaultValueAvailable()) ? $param->getDefaultValue() : "None";
echo $nl ."Is Array:\t\t";
echo ($param->isArray()) ? "Yes" : "No";
echo $nl . "Optional:\t\t";
echo ($param->isOptional()) ? "Yes" : "No";
echo $nl;
}
?>
To clarify the possibly confusing behavior of ReflectionParemeter::isArray(), it will return true if the parameter has type hinting:
<?php
...
public function __construct($no_default, $word = "Hello World", array $options = array('a', 'b'))
...
?>
Calling isArray() will now return true for the $options parameter