PHP inheritance

PHP inheritance

PHP inheritance introduction

Inheritance is a mechanism that extends and existing class. Inheriting a class would mean creating a new class with all functionality of the existing class in addition to some more. The created class is called as a subclass of the parent class. Parent is a keyword which we use to access members of a parent class. Inheritance is usually defined by using the keyword “Extend”. $this is used a reference to the calling object. Inheritance avoids redundancy of code.

Example:

Class employee extends manager : Here Employee is a subclass of manager.

Echo $this->name can be used to echo variable name of the parent class.

What type of inheritance that PHP supports? Provide an example.

PHP supports single level inheritance.

Inheriting a class would mean creating a new class with all functionality of the existing class in addition to some more. The created class is called as a subclass of the parent class. Parent is a keyword which we use to access members of a parent class. Inheritance is usually defined by using the keyword “Extend”. $this is used a reference to the calling object. Inheritance avoids redundancy of code.

Example:

Class employee extends manager : Here Employee is a subclass of manager.

Echo $this->name can be used to echo variable name of the parent class.
PHP overriding methods
PHP overriding methods
PHP objects & properties
Every class in PHP must have new instances or object created. This object must be assigned to a variable.
PHP access control modifier
Access control modifiers restrict the functions and classes to be accessed.
Post your comment
Discussion Board
PHP Supports Multilevel inheritance
PHP can support single level, multilevel,hierarchical and hybrid inheritance but not multiple inheritance because of diamond problem.
Sagar Salunkhe 10-18-2016