php5中this关键字用法讲解
欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 (3)parent 我们知道parent是指向父类的指针,一般我们使用parent来调用父类的构造函数。 ?php //基类 class Animal { //基类的属性 public $name; //名字 //基类的构造函数 public function __constr
欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入
(3)parent
我们知道parent是指向父类的指针,一般我们使用parent来调用父类的构造函数。
//基类
class Animal
{
//基类的属性
public $name; //名字
//基类的构造函数
public function __construct( $name ){
$this->name = $name;
}
}
//派生类
class Person extends Animal //Person类继承了Animal类
{
public $personSex; //性别
public $personAge; //年龄
//继承类的构造函数
function __construct( $personSex, $personAge ){
parent::__construct( "heiyeluren" ); //使用parent调用了父类的构造函数
$this->personSex = $personSex;
$this->personAge = $personAge;
}
function printPerson(){
print( $this->name. " is " .$this->personSex. ",this year " .$this->personAge );
}
}
//实例化Person对象
$personObject = new Person( "male", "21");
//执行打印
$personObject->printPerson(); //输出:heiyeluren is male,this year 21
?>
我们注意这么几个细节:成员属性都是public的,特别是父类的,是为了供继承类通过this来访问。我们注意关键的地方,第25行:parent:: __construct( "heiyeluren" ),这时候我们就使用parent来调用父类的构造函数进行对父类的初始化,因为父类的成员都是public的,于是我们就能够在继承类中直接使用this来调用。
[1] [2]

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

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.

win7 system is a very easy to use system. During the continuous use, many friends are asking how to enter safe mode in win7 system? Today, the editor will bring you a detailed tutorial with pictures and text on how to enter safe mode on a win7 computer. Let’s take a look. Graphical tutorial on how to enter safe mode in Windows 7: Method 1: Use shortcut keys to enter advanced startup items 1. Press the "F8" key repeatedly before booting to the Windows system startup screen, or hold down the "CTRL" key. In this way, we can enter the advanced startup options of the Windows system and choose to enter safe mode. Method 2: Set the boot to enter the advanced startup items 1. If the win7 system can start normally, you can use the Win key + R key combination to open the run box.

Classification and Usage Analysis of JSP Comments JSP comments are divided into two types: single-line comments: ending with, only a single line of code can be commented. Multi-line comments: starting with /* and ending with */, you can comment multiple lines of code. Single-line comment example Multi-line comment example/**This is a multi-line comment*Can comment on multiple lines of code*/Usage of JSP comments JSP comments can be used to comment JSP code to make it easier to read

How to use the exit function in C language requires specific code examples. In C language, we often need to terminate the execution of the program early in the program, or exit the program under certain conditions. C language provides the exit() function to implement this function. This article will introduce the usage of exit() function and provide corresponding code examples. The exit() function is a standard library function in C language and is included in the header file. Its function is to terminate the execution of the program, and can take an integer

WPS is a commonly used office software suite, and the WPS table function is widely used for data processing and calculations. In the WPS table, there is a very useful function, the DATEDIF function, which is used to calculate the time difference between two dates. The DATEDIF function is the abbreviation of the English word DateDifference. Its syntax is as follows: DATEDIF(start_date,end_date,unit) where start_date represents the starting date.

When we use a computer with the win10 operating system, if the computer has a black screen and only the mouse can move, don't worry. The editor thinks that most of this situation may be caused by a fault within the system, or because of a conflict with the driver of our system. You can try to use updates to upgrade the operating system, or reinstall the operating system and drivers to solve the problem. What to do if win10 has a black screen and cannot enter the desktop but the mouse can be moved. Method 1: 1. Hold down the Shift key and click "Restart" > Advanced Startup Options > Low Resolution Mode (or select low resolution mode after failing to start it for 3 times); 2. If During the installation program, press CTRL+SHIFT+F10, then system configuration, and then do

Introduction to Python functions: usage and examples of the abs function 1. Introduction to the usage of the abs function In Python, the abs function is a built-in function used to calculate the absolute value of a given value. It can accept a numeric argument and return the absolute value of that number. The basic syntax of the abs function is as follows: abs(x) where x is the numerical parameter to calculate the absolute value, which can be an integer or a floating point number. 2. Examples of abs function Below we will show the usage of abs function through some specific examples: Example 1: Calculation

Introduction to Python functions: Usage and examples of the isinstance function Python is a powerful programming language that provides many built-in functions to make programming more convenient and efficient. One of the very useful built-in functions is the isinstance() function. This article will introduce the usage and examples of the isinstance function and provide specific code examples. The isinstance() function is used to determine whether an object is an instance of a specified class or type. The syntax of this function is as follows
