php 遗产

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 遗产相关的知识,希望对你有一定的参考价值。

<?php
/*
=========== INHERITANCE ============
*/

class Car {
	// private $model; // SportsCar will not have access to this property
	protected $model; // this will work 

/*	THIS METHOD CAN NOT BE OVERRIDEN BY THE CHILD CLASS
	final public function hello() {
		echo 'FINAL: I am a ' . $this->model; 
	}
*/
	public function hello() {
		echo 'PARENT: I am a ' . $this->model; 
	}
	
	public function setModel( $model ) {
		$this->model = $model;
	}
	
}

class SportsCar extends Car {
	
	// this method overrides the hello method from its parent
	public function hello() {
		echo 'CHILD: I am a ' . $this->model ;
		
	}
}

// test
$sport1 = new SportsCar()  ; 
$sport1->setModel('BMW') ;
$sport1->hello() ;

echo PHP_EOL;

// EXAMPLE 2

class User {
	
	protected $username;
	
	public function setUsername( $uname ) {
		$this->username = $uname ; 
	}
	
}

class Admin extends User {
	public function sayHello() {
		return 'Hello admin, ' . $this->username;
	}
} 

$admin1 = new Admin() ;
$admin1->setUsername('armadillo') ;
echo $admin1->sayHello() ;


以上是关于php 遗产的主要内容,如果未能解决你的问题,请参考以下文章

INSPIRE PRO 无人机航拍在世界遗产江郎山三维重建的应用

INSPIRE PRO 无人机航拍在世界遗产江郎山三维重建的应用

INSPIRE PRO 无人机航拍在世界遗产江郎山三维重建的应用

对遗产进行分类

Makefile 中的“遗产”

markdown 遗产