Skip to content

Instantly share code, notes, and snippets.

@jk
Last active August 29, 2015 14:04
Show Gist options
  • Save jk/b1bfb94c7f276f53f46b to your computer and use it in GitHub Desktop.
Save jk/b1bfb94c7f276f53f46b to your computer and use it in GitHub Desktop.
Parameter #0 [ <required> BaseClass $baseClass ]
array(4) {
'type hinted class' =>
string(9) "BaseClass"
'position' =>
int(0)
'default value available?' =>
bool(false)
'variable / param name' =>
string(9) "baseClass"
}
<?php
class BaseClass {
function baseMethod($param) {
return $this;
}
}
class MyClass extends BaseClass {
function __construct() {
return $this;
}
function myMethod(BaseClass $baseClass, $other, $default = 'default') {
return $this;
}
}
$c1 = new ReflectionClass('BaseClass');
$c2 = new ReflectionClass('MyClass');
$c2m = $c2->getMethod('myMethod');
$c2mp = $c2m->getParameters();
$param = $c2mp[0];
$info = [
'type hinted class' => $param->getClass()->getName(),
'position' => $param->getPosition(),
'default value available?' => $param->isDefaultValueAvailable(),
'variable / param name' => $param->getName()
];
Reflection::export($param);
var_dump($info);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment