Skip to content

Instantly share code, notes, and snippets.

@janmarek
Created January 12, 2011 13:47
Show Gist options
  • Select an option

  • Save janmarek/776175 to your computer and use it in GitHub Desktop.

Select an option

Save janmarek/776175 to your computer and use it in GitHub Desktop.
<?php
interface ITest {
}
class TestClass1 {
}
class TestClass2 {
public function __construct(TestClass1 $param1, DateTime $param2, $param3) {
}
}
class TestClass3 extends TestClass2 {
}
class TestClass4 {
public function __construct(ITest $test) {
}
}
function getConstructorParamClasses($className) {
$classReflection = new ReflectionClass($className);
$constructorReflection = $classReflection->getConstructor();
if ($constructorReflection === NULL) {
return array();
}
$classes = array();
foreach ($constructorReflection->getParameters() as $paramReflection) {
$paramClass = $paramReflection->getClass();
$classes[] = $paramClass ? $paramClass->getName() : NULL;
}
return $classes;
}
echo '<pre>';
var_dump(getConstructorParamClasses("TestClass1"));
var_dump(getConstructorParamClasses("TestClass2"));
var_dump(getConstructorParamClasses("TestClass3"));
var_dump(getConstructorParamClasses("TestClass4"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment