Last active
August 29, 2015 14:13
-
-
Save jk/9a3446bfac1072c9521b to your computer and use it in GitHub Desktop.
Get parameter class type hint at runtime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Language | |
{ | |
public function getDefaultLanguage() | |
{ | |
return "en-US"; | |
} | |
} | |
class TestClass | |
{ | |
public function noLanguage($param1) | |
{ | |
return $param1; | |
} | |
public function withLanguage($param1, Language $language) { | |
return [ | |
$param1, | |
$language | |
]; | |
} | |
} | |
$r = new ReflectionClass('TestClass'); | |
$m = $r->getMethods(ReflectionMethod::IS_STATIC | ReflectionMethod::IS_PUBLIC); | |
foreach ($m as $method) { | |
$p = $method->getParameters(); | |
foreach ($p as $parameter) { | |
$c = $parameter->getClass(); | |
var_dump([ | |
'param' => $parameter->name, | |
'class' => $c->name, | |
'position' => $parameter->getPosition() | |
]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment