Created
March 24, 2017 11:17
-
-
Save edwardgalligan/ed3c25a043a7c4549c6cf9af30d10775 to your computer and use it in GitHub Desktop.
This file contains 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 | |
/** | |
* Quick utility function for dumping the public API of a class | |
*/ | |
function reflect($obj) { | |
$refl = new \ReflectionClass($obj); | |
$ret = array(); | |
foreach($refl->getConstants() as $const => $val) { | |
$ret[] = '::' . $const->name . ' = ' . $val; | |
} | |
foreach($refl->getProperties(\ReflectionProperty::IS_PUBLIC) as $prop) { | |
$ret[] = ($prop->isStatic()?'::':'->') . $prop->name . ' = ' . $prop->getValue(); | |
} | |
foreach($refl->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { | |
$params = array(); | |
foreach ($method->getParameters() as $param) { | |
$params[] = '$' . $param->name; | |
} | |
$ret[] = ($method->isStatic()?'::':'->') . $method->name . '(' . implode(', ', $params) . ')'; | |
} | |
return $ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment