inheritance - PHP __DIR__ evaluated runtime (late binding)? -


is somehow possible location of php file, evaluated @ runtime? seeking similar magic constant __dir__, evaluated @ runtime, late binding. similar difference self , static:

__dir__ ~ self   ???   ~ static 

my goal defining method in abstract class, using __dir__ evaluated respectively each heir class. example:

abstract class parent {   protected function getdir() {     // return __dir__; // not work     return <<i need this>>; //    } }  class heir extends parent {   public function dosomething() {     $heirdirectory = $this->getdir();     dostuff($heirdirectory);   } } 

obviously, problem occurs if parent , heir in different directories. please, take account. also, defining getdir on , on again in various heir classes not seem , option, that's why have inheritance...

you can add following code in getdir method of parent class

$reflector = new reflectionclass(get_class($this)); $filename = $reflector->getfilename(); return dirname($filename); 

your parent class this

abstract class parent {     protected function getdir() {         $reflector = new reflectionclass(get_class($this));         $filename = $reflector->getfilename();         return dirname($filename);     } } 

hoping help.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -