<?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教程有興趣的朋友有幫助。