Skip to content

Instantly share code, notes, and snippets.

@jmather
Forked from cordoval/gist:1854632
Created February 17, 2012 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmather/1854687 to your computer and use it in GitHub Desktop.
Save jmather/1854687 to your computer and use it in GitHub Desktop.
public function isEmpty()
{
$method = new \ReflectionMethod(
$this->_objectOrClassName,
$this->_methodName
);
list(,$path,) = explode(PHP_EOL, (string)$method);
preg_match('/(@@ )(.*\.php)( )(\d+)(\D*)(\d+)/', $path, $matches);
list ($path, $start, $end) = array(
$matches[2], $matches[4], $matches[6]
);
$code = '';
for ($i = $start; $i <= $end; $i++) {
$code .= Backtrace::readLine($path, $i);
}
$methodBodyPattern = "/function.*(?:{(.*)}|;)/sxU";
preg_match($methodBodyPattern, $code, $matches);
$extract = isset($matches[1]) ?: '';
return empty($extract);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment