作者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/m.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