Answer the question
In order to leave comments, you need to log in
How to implement property inheritance?
There are two classes: Parent and Child. Child will inherit the properties and methods of the parent. The parent has one property that is initialized when the class object is created. Later, in the parent, I create a "child" object.
class Parent {
protected $var = 0;
public function __construct($var=100) {
$this->var = $var;
}
protected function say() {
echo $this->var;
}
}
class Child extends Parent {
public function __construct() {
$this->say();
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question