<?php class Stu { private $name;//项目中变量的值都是外部传过来的 private $age; private $salary; public function __construct($name2,$age2,$salary2) //构造方法初始化,只要new就先执行 { $this->name = $name2; $this->age = $age2; $this->salary = $salary2; } public function info() { echo ‘姓名是‘.$this->name.‘年龄是‘.$this->age.‘工资是‘.$this->salary; } } $obj = new Stu(‘明哥‘,‘29‘,3000); $obj -> info();
原文:https://www.cnblogs.com/xm666/p/11253150.html