Home > Backend Development > PHP Tutorial > php 类 完整例子

php 类 完整例子

WBOY
Release: 2016-06-23 14:28:50
Original
955 people have browsed it

文件目录:

--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();?>
Copy after login

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(){			}}
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template