php examples-objects and classes

WBOY
Release: 2016-07-30 13:29:35
Original
906 people have browsed it
<?php
	class person{
		public $name;
		public $gender;
		public function say(){
			echo $this->name,"\tis",$this->gender,"\r\n" ;
		}
	}
	
	class family{
		public $people;
		public $location;
		public function __construct($p,$loc){               //显示声明一个构造方法且带参数
			$this->people = $p;
			$this->location = $loc;
		}
	}
	
	
	$student = new person();
	$student -> name = 'Tom';
	$student -> gender = 'male';
	$student -> say();
	$tom = new family($student,'peking');
	echo serialize($student);
	$student_arr = array('name'=>'Tom','gender'=>'male');
	echo "\n";
	echo serialize($student_arr);
	print_r($tom);
	echo "\n";
	echo serialize($tom);
?>
Copy after login

Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.

The above introduces PHP examples-objects and classes, including aspects of content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!