Skip to content

Instantly share code, notes, and snippets.

@edwardgalligan
Created March 24, 2017 11:17
Show Gist options
  • Save edwardgalligan/ed3c25a043a7c4549c6cf9af30d10775 to your computer and use it in GitHub Desktop.
Save edwardgalligan/ed3c25a043a7c4549c6cf9af30d10775 to your computer and use it in GitHub Desktop.
<?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