I have an abstract class “Class”. The class Subclass extends Class. The Class abstract class has the following call:
is_readable('some_file.ext')
How do I force the children of the abstract class to look for the file in the folder they are in, instead of the folder of the parent abstract class, without overriding the method in the children?
I.e. if abstract is in
classes/abstracts/Class.php
and the child is in
classes/children/Subclass.php,
how do I make Subclass.php look for some_file.ext in classes/children/ instead of classes/abstracts, without explicitly defining it in the Subclass?
You can use
ReflectionClass::getFileName()to retrieve the filenames in which the subclasses were defined.This works because
$thisno matter where it is defined will always refer to the instantiated class (and not it’s parent even though the$thisis found in the parent).