php之面向对象、构造函数、析构函数

时间:2021-05-22 00:12:50
 <!DOCTYPE HTML>
<html>
<head>
<title></title>
<meta charset="utf-8"/>
</head>
<body> </body>
</html>
<?php
class Site{
var $name;
var $url;
//构造函数
function __construct($name , $url){
$this->name = $name;
$this->url = $url;
}
//析构函数
function __destruct(){
echo PHP_EOL . "销毁函数";
}
function echoName(){
echo $this->name . PHP_EOL;
} function echoUrl(){
echo $this->url . PHP_EOL;
}
}
$baidu = new Site('百度' , 'www.baidu.com');
$baidu->echoName();
$baidu->echoUrl();
?>