Maison >développement back-end >tutoriel php >php实例-对象与类
<?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); ?>
版权声明:本文为博主原创文章,未经博主允许不得转载。
以上就介绍了php实例-对象与类,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。