Re: [請益] 放置 include 的地方

看板PHP作者 (小惡魔)時間16年前 (2009/03/18 15:17), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
include_once() 所指定的檔案被引入過了,那 include_once() 就不會再重複做一次引入的動作 確保不會重複引入相同檔案,而產生函數重複定義 (function redefinitions) 或者是變數重複給值 (value reassignments)。 ※ 引述《cpqq (cpqq)》之銘言: : 各位前輩, : 我如果把 include 放在 php 檔最前面,沒有辦法引用 include 檔內的變數, : 如果是把 include 放在 function 裡面就可以了,程式如下: : <?php // not working 會出現錯誤 : include_once 'config/config.inc.php'; : function displayMenu(){ : echo '<div id="menu"><ul>'; : ... : } : ?> : 如果是 : <?php //working 可正常輸出我所想要的 : function displayMenu(){ : include_once 'config/config.inc.php'; : echo '<div id="menu"><ul>'; : ... : } : ?> : 請問為什麼會這樣呢?謝謝 -- Appleboy Blog: http://blog.Wu-Boy.com -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 219.70.25.236 ※ 編輯: appleboy46 來自: 219.70.25.236 (03/18 15:17)
文章代碼(AID): #19mA0Hjm (PHP)
討論串 (同標題文章)
文章代碼(AID): #19mA0Hjm (PHP)