-2
Suppose there is a class and in its constructor it is necessary to call a function that is only defined in classes that inherit it. What is necessary for this to happen?
Sample code:
interface A {
public function hello();
}
abstract class B implements A {
public function __contruct() {
if (method_exists($this, "hello"))
{
$this->hello();
}
}
}
class C extends B {
public function __contruct() {
parent::__construct();
}
public function hello() {
echo "Hello world!";
}
}
$B = new C();
This code returns nothing, but should return "Hello World!".
PS: I thought about abstract methods, but also I didn’t get the expected return.
you have created an implementation rule and not implemented in the class! gives an error that ai.
– novic
another problem
hello()
is a class C method does not give class B! has problem too, ie if you are doing something you do not understand.– novic
also has typo.
– novic