[請益] 建構子執行順序

看板PHP作者 ( )時間11年前 (2014/06/25 07:57), 編輯推噓2(206)
留言8則, 5人參與, 最新討論串1/1
'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(); 第一種寫法會抓不到值, 第二種則可以 想不太通原因, 求大大解答, 謝謝! --

12/24 10:39,
If 薪水<28K Then 離職
12/24 10:39

12/24 11:18,
else 跳槽
12/24 11:18

12/24 12:30,
goto 買樂透XD
12/24 12:30

12/24 12:41,
應該加入 #include"把上董事長女兒.h" 這個函式庫 :p
12/24 12:41

12/24 16:05,
樓上有.h沒有lib也是夢一場 include大家都會阿
12/24 16:05

12/24 19:11,
Error: invalid path
12/24 19:11
-- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 203.217.117.113 ※ 文章網址: http://www.ptt.cc/bbs/PHP/M.1403654276.A.4A9.html

06/25 10:38, , 1F
google: php properties, 第一段
06/25 10:38, 1F

06/25 10:39, , 2F
前略...this initialization must be a constant value
06/25 10:39, 2F

06/25 10:41, , 3F
你第一種應該會報錯才對,寫法錯誤。
06/25 10:41, 3F

06/25 12:16, , 4F
不會改的東東為什麼要放在$_SESSION裡面…
06/25 12:16, 4F

06/26 02:06, , 6F
debug時請先 ini_set('display_errors', 'On');
06/26 02:06, 6F

06/26 07:31, , 7F
謝謝提供關鍵字和相關資料
06/26 07:31, 7F

06/26 07:32, , 8F
除錯有開, 是不懂為什麼這樣有bug, 算是對class不夠了解
06/26 07:32, 8F
文章代碼(AID): #1JgX24If (PHP)
文章代碼(AID): #1JgX24If (PHP)