1 <?php 2 declare(encoding='UTF-8'); 3 class Site{ 4 /*成员变量*/ 5 var $url; 6 var $title = "gunduzi" 7 8 /*成员函数*/ 9 function setUrl($par){ 10 $this->url = $par; 11 } 12 13 function getUrl(){ 14 echo $this->url . PHP_EOL; 15 } 16 17 function setTitle($par){ 18 $this->title = $par; 19 } 20 21 function getTitle(){ 22 echo $this->title . PHP_EOL; 23 } 24 } 25 /*调用成员变量*/ 26 $baidu = new Site; 27 $baidu.setUrl("www.baidu.com"); 28 $baidu.setTitle("百度"); 29 30 $baidu->getUrl(); 31 $baidu->getTitle(); 32 ?>