Change language

PHP multiple inheritance

Traits (using the class in conjunction withtraits):trait - it is a class type that allows multiple inheritance. Classes, case classes, objects, and characteristics can extend at most one class, but they can simultaneously extend several characteristics. 
Syntax:
class child_class_name extends parent_class_name {use trait_name; ... ... child_class functions} 
Example :  
// Geek class class Geeks { public function sayhello() { echo " Hello " ; } }  
// Trait forGeeks trait forGeeks { public function sayfor() { echo "Geeks" ; } } class Sample extends Geeks { use forGeeks; public function engineerforengineer() { echo "GeeksforGeeks" ; } } $test = new Sample(); $test -> sayhello(); $test -> sayfor(); $test -> engineerforengineer(); ?>
Exit:
Hello Geeks GeeksforGeeks 
In the above program, "traits" were used in conjunction with the parent class. There is a “class” named “Geeks” that contains a sayhello() function and a “trait” named “forGeeks” that contains a function engineerforengineer() and there is a child class named “Sample” and we create an object of this class with name "test" and using it, we call all the functions of the class and trait. Traits (using multiple traits): You can insert several traits into a class by listing them in the use statement by separating them with commas. 
Syntax:
class child_class_name {use trait_name; ... ... child_class functions} 
Example :  
// geeky hell trait Geeks { public function sayhello() { echo " Hello " ; } }  
// forGeeks trait trait forGeeks { public function sayfor ( ) { echo "Geeks" ; } } class Sample { use Geeks; use forGeeks; public function engineerforengineer() { echo "GeeksforGeeks" ; } } $test = new Sample(); $test -> sayhello(); $test -> sayfor(); $test -> engineerforengineer(); ?>
Exit:
Hello Geeks GeeksforGeeks 
The above program used "traits". There are two traits named “Geeks” that contain the sayhello() and “forGeeks” functions, which contain the engineerforengineer() function respectively, and there is a child class named “Sample” and we create an object of that class named “test” and use it we call all dash functions.Interface (using a class together with an interface):
Syntax:
class child_class_name extends parent_class_name implements interface_name1, ... 
Example : class A { public function insideA() { echo "I am in class A" ; } } interface B { public function insideB(); } class Multiple extends A implements B { function insideB() {

echo "I am in interface" ; } public function insidemultiple() { echo "I am in inherited class" ; } } $engineer = new multiple(); $engineer -> insideA(); $engineer -> insideB(); $engineer -> insidemultiple(); ?> Exit:
I am in class AI am in interface I am in inherited class 
In the above program, interface "B" was used together with class "A" to implement multiple inheritance. It is important to remember that it cannot define a function inside an interface, it must be defined inside a child class "Multiple". We call all functions using a child class object (Multiple) named "engineer". Interface (using multiple interfaces): Syntax:
class child_class_name implements interface_name1, interface_name2, ... 
Example : interface C { public function insideC(); } interface B { public function insideB(); } class Multiple implements B, C { // Interface function B function insideB() { echo " I am in interface B " ; } // C interface function function insideC() { echo "I am in interface C" ; } public function insidemultiple() { echo "I am in inherited class" ; } } $engineer = new multiple(); $engineer -> insideC(); $engineer -> insideB(); $engineer -> insidemultiple(); ?> Exit:
I am in interface CI am in interface BI am in inherited class 
In the above program, several interfaces have been used to implement multiple inheritance. In the above example, there are two interfaces named “B” and “C” that act as base classes, and there is a child class named “Multiple” and we call all functions using its object named “engineer”.

Shop

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Best laptop for engineering student

$

Best laptop for development

$

Best laptop for Cricut Maker

$

Best laptop for hacking

$890

Best laptop for Machine Learning

$950

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method