Blogger Information
Blog 13
fans 0
comment 0
visits 11106
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php类重载
linuxup的博客
Original
781 people have browsed it
<?php
header("Content-type:text/html;charset=utf-8"); //设置输出编码格式
class Test{   //创建一个类
	protected $name;
	protected $age;


	function __construct($name,$age){
			$this->name=$name;
			$this->age=$age;
	}

public	function __call($functionName,$agrument){   //调用不存在的方法会自动调用魔术方法__call,并可以把方法\参数传进来显示
		echo "你调用的函数名称".$functionName."不存在!<br>".print_r($agrument)."参数不存在!";
	}

	public function func(){
		echo "test";
	}

public	function get(){
		echo "我的名字是{$this->name},我的年龄是{$this->age}";
	}
}

$a = new Test('李某某','18');
$a->func();
echo "<br>";
$a->logo('123','1234','abc');

echo "<br>";

$a->get();
echo "<br>";
class Test1 extends Test{
	protected $school;
	function __construct($name,$age,$school){
     parent::__construct($name,$age); //重载父类的构造函数
     $this->school = $school;  //增加一个成员属性
	}
	public function get(){
		parent::get();  //重载父类方法
		echo "我在{$this->school}学校读书";
	}
}


$b=new test1('李某某','18','北京清华大学');  //实例类

echo $b->get();  //调用方法


Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post