I've been searching for an answer all day, but I can't seem to find one. Sorry if I don't make much sense, I'm losing my mind over this.
Here's what I'm trying to do:
abstract class Parent {
abstract public function Test();
}
class Child1 extends Parent {
abstract public function Test() {
echo "Test!";
}
}
class Child2 extends Parent {
public function Test2() {
echo "Test2!";
$this->Test(); // Child1::Test();
}
}
Again, sorry if I'm not making much sense. I will try to explain more if you need me to.
You are missing the concept of abstract classes and methods.
Abstract classes are classes that define some basic behavior and cannot be instantiated. They are designed to be subclassed.
These are methods that need to be implemented by the extending class. Like interfaces abstract methods define behavior without an implementation.
In your code you declared an abstract class with an abstract method.
abstract class Parent {
public abstract function Test();
}
When another class subclasses Parent it must implement the abstract method making it concrete.
class Child extends Parent {
public function Test() {
echo "Test!";
}
}
A class or instance has no concept of a sibling. A class cannot know who subclasses its parent and access it in a static way.
It's not an OOP pattern, and not available in any OOP language that I kow of (except for introspection magic): Child2 do not know anything (and does not have to) about Child1 class. they could be defined independently.
I think that at this point you should explain what your needs are. I guess we could help you ,with some design pattern.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With