阅读背景:

php实例化类

来源:互联网 

一 代码

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


你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: