Pleace consider the following example:
class A {
public method() {
$foo = 'bar';
}
}
class B extends A {
public method {
parent::method();
echo $foo; // $foo == null
}
}
I run to situations like this quite frequently when I need to extend the functionality of a class coded by somebody else. Is there a way to have the $foo
of the aforementioned example to be not null
but bar
?
I know perfectly well, that what I'm suggesting is not a problem at all if the variable $foo
were a property of the class. However, this example applies to a situation where the class I want to extend is poorly designed and modifying the original class and changing the rogue variables into class properties is out of the question for reasons such as the class being a part of a CMS and update compatibility etc.