php实例化类

阅读更多

一 代码

name = $name;
		$this->age = $age;
	} 
	
	public function getNameAndAge()     //定义类的成员方法
	{
	    return "学生" . $this->name . "今年" . $this->age . "周岁";
	}
 
}
$student = new Student("小明", 15);    //类的实例化
echo $student->getNameAndAge();    //调用类的成员方法
?>

 

二 运行结果
学生小明今年15周岁

你可能感兴趣的:(php,类)