<?php class Page {private $title; //构造函数固定名称为__construct,这样能将php的类构造函数独立于类名,以后修改类名就无需修改构造函数名称 function __construct($param, $title) { $this->title = $title; echo "construct is running!, and param is ".$param."<br>"; } function _get($name) { return $this->$name; } } $page = new Page("haha", "title1111111");?>
红色部分为实例变量的获取,请注意,以下是不正确的:
① $title
② $this->$title