文件目录:
--index.php
--php
--data_info.php
index.php
这里要require_once类所在的php文件
<?phprequire_once('./php/data_info.php'); $oneData=new user; $oneData->setName("username"); $oneData->setPassword("password"); echo $oneData->getName(); echo $oneData->getPassword();?>
data_info.php
<?phpclass user{ var $name; var $password; public function __construct(){ } public function setName($name){ $this->name=$name; } public function getName(){ return $this->name; } public function setPassword($password){ $this->password=$password; } public function getPassword(){ return $this->password; } function __destruct(){ }}