Home Backend Development PHP Tutorial Sample code for simple implementation of multiple inheritance in PHP5

Sample code for simple implementation of multiple inheritance in PHP5

Mar 31, 2017 pm 03:23 PM

By studying the PHP language, we can know that PHP4 cannot implement multiple inheritance. So what about PHP5? We conducted a test on PHP5 and found that the implementation method of multiple inheritance in PHP5 is very simple.

PHPUploadSpecific usage of class upload.php

How to use PHP Ajax to achieve refresh-free upload of images

Analysis of the specific use of PHP5destructor

Specific application of PHP5 magic function

The following is the specific code for PHP5 multiple inheritance: The output structure is

The above is a sample code to simply implement multiple inheritance in PHP5 For more related content, please pay attention to the PHP Chinese website (www.php.cn)!
<? 
//PHP5 接口 ---跟 JAVA一个鸟样~ 晕  
interface IFOne{  
 function getName();  
}  
interface IFTwo{  
 function getID();  
}  
//PHP 抽象类   
abstract class AbsClsOne{  
 var $name;  
 function setName($name){  
  $this->name=$name;  
 }  
}  
abstract class AbsClsTwo{  
 var $id;  
 function setID($id){  
  $this->id=$id;  
 }  
}  
//单继承 多实现  
class ExtendsMoreCls extends AbsClsOne implements IFOne,IFTwo{  
 var $id;  
 private static $priVar="private";  
 function construct(){//PHP5的 构造函数  
  self::$priVar="set private";  
  $this->id=0;   
 }   
 function destruct(){//释构函数  
  echo "ExtendsMoreCls destruct";  
 }  
 function getName(){  
  return $this->name;  
 }  
 function getID(){  
  return $this->id;  
 }  
 public static function clsStaticFunc(){  
  echo "static function";  
 }  
}  
 
$emc=new ExtendsMoreCls();  
$emc->setName("kj021320");  
echo $emc->getName();  
echo "<br>";   
echo $emc->getID();  
echo "<br>";  
ExtendsMoreCls::clsStaticFunc();//调用静态方法  
echo "<br>";  
?>
Copy after login

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the difference between php5 and php8 What is the difference between php5 and php8 Sep 25, 2023 pm 01:34 PM

The differences between php5 and php8 are in terms of performance, language structure, type system, error handling, asynchronous programming, standard library functions and security. Detailed introduction: 1. Performance improvement. Compared with PHP5, PHP8 has a huge improvement in performance. PHP8 introduces a JIT compiler, which can compile and optimize some high-frequency execution codes, thereby improving the running speed; 2. Improved language structure, PHP8 introduces some new language structures and functions. PHP8 supports named parameters, allowing developers to pass parameter names instead of parameter order, etc.

How to deal with multiple inheritance and interface conflicts in C# development How to deal with multiple inheritance and interface conflicts in C# development Oct 10, 2023 am 08:05 AM

How to deal with multiple inheritance and interface conflicts in C# development requires specific code examples. Although multiple inheritance is not supported in C#, similar functions can be achieved through interfaces. However, using multiple interfaces may lead to conflicting interface methods. In this article, we'll discuss how to handle this situation and provide some practical code examples. Reasons for interface conflicts In C#, a class can implement multiple interfaces. If there are methods with the same name in multiple interfaces, method conflicts will occur. For example, we define two interfaces IInterface1

How to change port 80 in php5 How to change port 80 in php5 Jul 24, 2023 pm 04:57 PM

How to change port 80 in php5: 1. Edit the port number in the Apache server configuration file; 2. Edit the PHP configuration file to ensure that PHP works on the new port; 3. Restart the Apache server, and the PHP application will start running on the new port. run on the port.

How to solve Python's multiple inheritance error? How to solve Python's multiple inheritance error? Jun 25, 2023 am 08:11 AM

Python is an object-oriented programming language that supports multiple inheritance. In the process of multiple inheritance, various errors are often encountered, such as the "diamond inheritance" problem, that is, multiple subclasses inherit from the same parent class at the same time. This This will lead to problems such as increased code complexity and difficulty in maintenance. This article will introduce how to solve multiple inheritance errors in Python. 1. Use super() In Python, you can use the super() function to avoid problems caused by multiple inheritance. When calling a parent class method in a subclass, you can

How to solve the problem that php5 is not listening on port 9000 How to solve the problem that php5 is not listening on port 9000 Jul 10, 2023 pm 04:01 PM

Solution steps for php5 not listening to port 9000: 1. Check the PHP-FPM configuration file; 2. Restart the PHP-FPM service; 3. Turn off the firewall or configure port forwarding; 4. Check whether other processes occupy port 9000.

What is the difference between php7 and php5 syntax What is the difference between php7 and php5 syntax Jul 10, 2023 pm 03:25 PM

The syntax differences between php7 and php5 are: 1. PHP7 introduces strict type declarations, while the type of PHP5 variables is implicit; 2. PHP7 introduces support for scalar type declarations, but PHP5 does not; 3. PHP7 introduces NULL Merge operator, while PHP5 checks whether a variable exists and is not null, you need to use a conditional statement; 4. PHP7 adds a new comparison operator "<=>", but PHP5 does not; 5. PHP7 introduces a new feature anonymous class , while PHP5 does not.

Compare interface inheritance and multiple inheritance in Java Compare interface inheritance and multiple inheritance in Java Jan 03, 2024 am 09:38 AM

Comparison of Interface Inheritance and Multiple Inheritance in Java In Java, an interface is an abstract type that defines methods and constants. Interfaces can be implemented by classes, and a class can implement multiple interfaces. In the implementation of interfaces, there are two methods: interface inheritance and multiple inheritance. This article will discuss the differences between the two methods and give specific code examples to deepen understanding. Inheritance of interfaces Inheritance of interfaces means that one interface can inherit from another interface, and the methods and constants in the inherited interface will also be inherited. Interface inheritance uses the keyword exte

Detailed explanation of multiple inheritance issues in C++ Detailed explanation of multiple inheritance issues in C++ Oct 08, 2023 am 10:01 AM

Detailed explanation of multiple inheritance issues in C++ Introduction In C++, multiple inheritance is a feature that allows a derived class to inherit properties and behaviors from multiple base classes. However, since multiple inheritance introduces some complexity, developers must handle it carefully to avoid potential problems. This article will discuss the issue of multiple inheritance in C++ in detail and provide specific code examples. Basic Concepts Multiple inheritance allows a derived class to inherit properties and methods from multiple base classes. For example, we can define a base class called Animal and then define a base class called B

See all articles