May 2016
Intermediate to advanced
155 pages
2h 15m
English
© Mikael Olsson 2016
Mikael Olsson, PHP 7 Quick Scripting Reference, 10.1007/978-1-4842-1922-5_10
Mikael Olsson1
(1)Hammarland, Finland
Inheritance allows a class to acquire the members of another class. In the following example, the Square class inherits from Rectangle, specified by the extends keyword. Rectangle then becomes the parent class of Square, which in turn becomes a child class of Rectangle. In addition to its own members, Square gains all accessible (non-private) members in Rectangle, including any constructor.
// Parent class (base class)class Rectangle{public $x, $y;function __construct($a, $b){$this->x = $a;$this->y = $b;}}// Child class (derived class)class Square extends Rectangle {}
When creating an ...
Read now
Unlock full access