程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> PHP綜合 >> 解析thinkphp import 文件內容變量失效的問題

解析thinkphp import 文件內容變量失效的問題

編輯:PHP綜合
用TP 集成支付寶賬戶綁定功能時碰上個問題
ORM 下有文件 config.class.php
直接import()後 發現裡面的變量無法使用  但確實是加載咯。。(在config.class.php輸出內容成功)
思考百度了半天。。
原來一直知道 JS 作用域 忽略了 PHP 函數也有作用域的- -
具體原理:
復制代碼 代碼如下:
<?php
class b{
   function test(){
      myImport("a.php");
      $testClass = new impClass();
      $testClass->test();
      echo $a."from b";
   }
}
class a{
   function funa(){
      $InsB = new b();
      $InsB->test();
   }
}
function myImport($file){
   require $file;
   echo $a."from myImport";
}
$InsA = new a();
$InsA->funa();
?>
a.php
<?php
$a = "a";
class impClass{
   function test(){
      echo "import success";
   }
}
?>

顯示:
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved