PHP构造函数和析构函数
时间:6年前 阅读:5971
<?php
class dog{
	var $name;
//	php 将所有以__(两个下划线)开头的类方法保留为魔术方法。
//	所以在定义类方法时,除了魔术方法,建议不要以__为前缀
//	construct 构成;建造   构造函数声明必须是__construct()
	function __construct($n){
		$this->name = $n;
	}
	function bark(){
		echo $this->name."wang";
	}
}
$mydog = new dog("zhangsan");
$mydog->bark();
?> 
本站声明:网站内容来源于网络,如有侵权,请联系我们https://www.qiquanji.com,我们将及时处理。
                        微信扫码关注
更新实时通知



网友评论