例2输出结果为:变数name未定义 , 初始化为0变数name被初始化为:0__construct() , __destruct()简介:- 在每次创建新对象时先调用此方法-对象的所有引用都被删除或者当对象被显式销毁时执行实例3:【魔术方法】<?php/** * 清晰的认识__construct() __destruct */class Example { public static $link; //在类实例化的时候自动载入__construct这个方法 public function __construct($localhost, $username, $password, $db) { self::$link = mysql_connect($localhost, $username, $password); if (mysql_errno()) { die('错误:' . mysql_error()); } mysql_set_charset('utf8'); mysql_select_db($db); } /** * 通过__construct连结好资料库然后执行sql语句...... */ //当类需要被删除或者销毁这个类的时候自动载入__destruct这个方法 public function __destruct() { echo '<pre>'; var_dump(self::$link); mysql_close(self::$link); var_dump(self::$link); }}$mysql = new Example('localhost', 'root', 'root', 'test');例3输出结果为:resource(2) of type (mysql link)resource(2) of type (Unknown)
- 去皱面膜自制方法
- 扁桃体发炎的症状和治疗方法
- 鱼子酱营养价值及食用方法
- 地理信息系统原理与方法
- 决明子的功效与作用及食用方法
- 百日咳治疗方法偏方
- 蛋清去黑头的方法
- 颈椎病食疗方法
- 体癣最好治疗方法
- 精华油的正确使用方法