作者m7m123d ( )
看板PHP
标题[请益] 建构子执行顺序
时间Wed Jun 25 07:57:40 2014
'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();
第一种写法会抓不到值, 第二种则可以
想不太通原因, 求大大解答, 谢谢!
--
1F:推 Non:If 薪水<28K Then 离职12/24 10:39
2F:→ maddman:else 跳槽 12/24 11:18
3F:→ tsming:goto 买乐透XD12/24 12:30
4F:推 YUKIKASE:应该加入 #include"把上董事长女儿.h" 这个函式库 :p12/24 12:41
5F:推 smallworld:楼上有.h没有lib也是梦一场 include大家都会阿 12/24 16:05
6F:→ PUTOUCHANG:Error: invalid path12/24 19:11
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 203.217.117.113
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/PHP/M.1403654276.A.4A9.html
7F:推 meteorsok:google: php properties, 第一段 06/25 10:38
8F:→ meteorsok:前略...this initialization must be a constant value 06/25 10:39
9F:推 meteorsok:你第一种应该会报错才对,写法错误。 06/25 10:41
10F:→ MOONRAKER:不会改的东东为什麽要放在$_SESSION里面… 06/25 12:16
12F:→ up9cloud:debug时请先 ini_set('display_errors', 'On'); 06/26 02:06
13F:→ m7m123d:谢谢提供关键字和相关资料 06/26 07:31
14F:→ m7m123d:除错有开, 是不懂为什麽这样有bug, 算是对class不够了解 06/26 07:32