Skip to content

Instantly share code, notes, and snippets.

@userlond
Last active January 28, 2019 04:38
Show Gist options
  • Save userlond/e3d99d8c270c9d2f838db05417b822f9 to your computer and use it in GitHub Desktop.
Save userlond/e3d99d8c270c9d2f838db05417b822f9 to your computer and use it in GitHub Desktop.
Get absolute path of class file by its object
<?php
/**
* Get absolute path of class file by its object
* @param $object Object instance
* @return string|null
*/
function get_absolute_path_to_class_filename_by_object($object)
{
$className = get_class($object);
try {
$reflection = new \ReflectionClass($className);
} catch (ReflectionException $e) {
return null;
}
return $reflection->getFileName();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment