Home > php教程 > php手册 > body text

简单实用的php类

WBOY
Release: 2016-06-21 09:16:06
Original
1305 people have browsed it

适合初学者使用的PHP类,建意做站时多封装成类,模块化,那样程序就会清晰多了。。

一个非常简单的php类,其实类到底是个什么东西,我也说不清楚,说白来就是许多函数都集合吧。放在一块一起使用。通过下面这个简单都例子,相信你一定会使用php的类了。

例(附使用方法):

//定义一个类名为Test的类
class Test
{
var $id;
var $main;
function setid($id){
   $this->id = $id;
}
function setmain($main){
   $this->main = $main;
}
function getid(){
   return $this->id;
}
function getmain(){
   return $this->main;
}
function returninfo(){
$returninfo = $this->id;
$returninfo = $returninfo.':';
$returninfo .= $this->main;
$returninfo .= '
';
return $returninfo;
}
}

?>

//使用方法
$testinfo = new Test;
$testinfo->setid(1);
$testinfo->setmain('测试内容阿斯蒂芬');
echo $testinfo->returninfo();

$testinfo->setid(2);
$testinfo->setmain('测试内容阿斯蒂芬阿斯蒂芬');
echo $testinfo->returninfo();
?>



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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template