tags:

views:

38

answers:

1

I have two classes in separate folders

class Parent
{
    public $path = null;

    function  __construct()
    {
        $this->path = __DIR__;
    }
}

and

class Child extends Parent
{

}

So when I create an instance of Child:

$child = new Child();
echo $child->path

I get a path to Parent. What I actually want is to get path to Child. I cannot modify Child class.

Is it possible?

+1  A: 

You can get use reflection to get what you're looking for:

$child = new Child();
$class_info = new ReflectionClass($child);
echo dirname($class_info->getFileName());
bradym
Thanks, bradym. That's what I need.
ehpc
If that works, please mark the answer as accepted by clicking the checkbox. That will remove this from the "unanswered questions" list.
bradym
I already did that, but it seems that yesterday glitch at stackoverflow rolled it back..
ehpc