文件目录:
--index.php
--php
--data_info.php
index.php
这里要require_once类所在的php文件
<?php
require_once('./php/data_info.php');$oneData=new user;$oneData->setName("username");$oneData->setPassword("password");echo $oneData->getName();echo $oneData->getPassword();
?>
data_info.php
<?php
class 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(){}
}
构造与析构,遥想当年,java学了好多年后,才适应了这两个方法。。