I have a project. I need to get the contents of a file in a package. I could do it the hard way:
file_get_contents('../../vendor/{vendor}/{package}/src/
    {directory}/{sub-directory}/class.php');
Or, I could do it the "easy way," which I'm pretty sure is impossible.
namespace MyVendor\MyProject;
use TheirVendor\TheirPackage\TheirClass;
class MyObject
{
    public function myFunction()
    {
        return file_get_contents(TheirClass);
    }
}
Is this (or something like it) possible?
You can get the file name of where a class is declared using a ReflectionClass instance and its getFileName() method:
$reflector = new ReflectionClass(\Vendor\Package\Class::class);
echo $reflector->getFileName();
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With