__FILE__ and inheritance
Posted: Wed Oct 29, 2008 10:28 pm
This can't be a new problem, but its one I can't seem to tackle (and neither can google, lol).
I'm trying to find a way to get the filename of a subclass from a function defined in its parent class. I get that __FILE__ isn't going to work directly since it always returns the filename of the file it was used in, but there has to be someway short of redeclaring such a simple function in each and every sub class, right?
assuming this layout, getFile() will always return SuperClass.php, regardless if it is called from SubA or SubB, is there anyway (anyway at all, dirty code or otherwise) to get getFile() to return SubA.php and SubB.php respecticely....short of redefining getFile() in each of the sub classes?
Thanks for your time,
Aaj
I'm trying to find a way to get the filename of a subclass from a function defined in its parent class. I get that __FILE__ isn't going to work directly since it always returns the filename of the file it was used in, but there has to be someway short of redeclaring such a simple function in each and every sub class, right?
Code: Select all
//SuperClass.php
class SuperClass
{
public function getFile()
{
return __FILE__;
}
}
//SubA.php
class SubA extends SuperClass{}
//SubB.php
class SubB extends SuperClass{}
Thanks for your time,
Aaj