Last active
January 28, 2019 04:38
-
-
Save userlond/e3d99d8c270c9d2f838db05417b822f9 to your computer and use it in GitHub Desktop.
Get absolute path of class file by its object
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 | |
/** | |
* 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