Blogger Information
Blog 28
fans 0
comment 0
visits 15741
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
2018-8-29类和对象+数据库连接
阿小的博客
Original
502 people have browsed it

实例

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>类和对象的简单介绍+数据库连接</title>
</head>
<body>
<span>类是一类实物的集合,在PHP中用calss 类名{}来声明类,类中包含成员属性(变量)和成员方法(函数)</span><br>
<span>对象是类的实例化,在PHP中用new 类名  来实例化一个对象,用->来访问类的属性和方法</span><br>
<span>类是对象的集合,对象是类的实例化,比如声明一个car类,类里有$color,$price等属性,run()方法;实例化一个轿车,他就是car的一个实例化,他可以继承car的属性和方法</span>
<hr>
<?php 
class Person 
{
	//private私有变量,外部不能直接访问
	private $name;
	private $sex;
	private $age;
	
	private function eat()
	{
		return '吃饭';
	}
	
	private function shopping()
	{
		return '购物';
	}
	
	//构造函数 __(双下划线),对象实例化时自动创建
	public function __construct()
	{
		$this->name = $name;
		$this->sex = $sex;
		$this->age = $age;
		
		$this->eat()=eat();
	}
	
	public function __set()
	{
		$this->name= $name;
	}
	
	public function get()
	{
		return $name;
	}
	
	
}
?>


<?php 

?>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例


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