Get the file name of a instantiated class

abstract-class, class, php

Solution

What you need is the `ReflectionObject` class and its method, `ReflectionClass::getFileName`.

$reflection_class = new ReflectionClass(get_class($this));
echo $reflection_class->getFileName();

Check the function's manual here.

Problem

Let's say I got the class name with `get_class($this)` within an abstract class method. How can I also get the file name in which this class was defined? (full path) I know I could pass it as an argument to my child class and create a property which is accessible in the parent class, but I was wondering if PHP has something built-in

Original source