[请益] 建构子执行顺序

楼主: m7m123d ( )   2014-06-25 07:57:40
'config.php'
$_SESSION['ROOT'] = 'www.test.com.tw';
## 第一种写法 ##
require_once('config.php');
class test{
public $rootUrl = $_SESSION['ROOT'];
function __construct(){
}
function getRoot(){
return $this->rootUrl;
}
}
## 第二种写法 ##
require_once('config.php');
class test{
public $rootUrl;
function __construct(){
$this->rootUrl = $_SESSION['ROOT'];
}
function getRoot(){
return $this->rootUrl;
}
}
$test = new test();
$test->getRoot();
第一种写法会抓不到值, 第二种则可以
想不太通原因, 求大大解答, 谢谢!
作者: meteorsok (花花小蛋糕)   2014-06-25 10:38:00
google: php properties, 第一段前略...this initialization must be a constant value你第一种应该会报错才对,写法错误。
作者: MOONRAKER (㊣牛鹤鳗毛人)   2014-06-25 12:16:00
不会改的东东为什么要放在$_SESSION里面…
作者: gname ((′口‵)↗︴<><...<><)   2014-06-25 12:41:00
作者: up9cloud (九天)   2014-06-26 02:06:00
debug时请先 ini_set('display_errors', 'On');
楼主: m7m123d ( )   2014-06-26 07:31:00
谢谢提供关键字和相关资料除错有开, 是不懂为什么这样有bug, 算是对class不够了解

Links booklink

Contact Us: admin [ a t ] ucptt.com