So I have this simple code:
<?php
class TestClass {
public function test_function($id, $values = array())
{
$ref_met = new ReflectionMethod(__METHOD__);
foreach($ref_met->getParameters() as $param) {
if($param->isArray()) {
echo "$param->name is an array\n";
} else {
echo "$param->name is NOT an array\n";
}
}
}
}
$t = new TestClass();
$t->test_function(5, array());
The $values method argument is an array, you can tell in the function definition, however, if I use reflection to get the method parameters information they always return as not being an array.
I can try even extracting the reflection relevant code to another separate function so that It does not execute on the method itself, but to no avail:
<?php
class TestClass {
public function test_function($id, $values = array())
{
}
}
function test_reflection()
{
$ref_met = new ReflectionMethod('TestClass::test_function');
foreach($ref_met->getParameters() as $param) {
if($param->isArray()) {
echo "$param->name is an array\n";
} else {
echo "$param->name is NOT an array\n";
}
}
}
test_reflection();
Is there something I'm not understanding about reflection on PHP? I've read and re-read the documentation but I can't find anything that tells me I'm doing something wrong.
I'm using PHP 5.4.20, if that matters.