解析thinkphp import 文件內(nèi)容變量失效的問題
更新時間:2013年06月20日 16:14:44 作者:
本篇文章是對thinkphp import文件內(nèi)容變量失效的問題進行了詳細的分析介紹,需要的朋友參考下
用TP 集成支付寶賬戶綁定功能時碰上個問題
ORM 下有文件 config.class.php
直接import()后 發(fā)現(xiàn)里面的變量無法使用 但確實是加載咯。。(在config.class.php輸出內(nèi)容成功)
思考百度了半天。。
原來一直知道 JS 作用域 忽略了 PHP 函數(shù)也有作用域的- -
具體原理:
<?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";
}
}
?>
顯示:
ORM 下有文件 config.class.php
直接import()后 發(fā)現(xiàn)里面的變量無法使用 但確實是加載咯。。(在config.class.php輸出內(nèi)容成功)
思考百度了半天。。
原來一直知道 JS 作用域 忽略了 PHP 函數(shù)也有作用域的- -
具體原理:
復制代碼 代碼如下:
<?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";
}
}
?>
顯示:
相關(guān)文章
php下將圖片以二進制存入mysql數(shù)據(jù)庫中并顯示的實現(xiàn)代碼
php把圖片存入mysql教程數(shù)據(jù)庫教程中并在網(wǎng)頁上顯示,一般情況下并不需要將突破保存到數(shù)據(jù)庫中,不論是異地備份還是什么的,都很麻煩,特殊需要的除外。2010-05-05
PHP的curl實現(xiàn)get,post和cookie(實例介紹)
本篇文章是對PHP的curl實現(xiàn)get,post和cookie的方法進行了詳細的分析介紹,需要的朋友參考下2013-06-06
用PHP與XML聯(lián)手進行網(wǎng)站編程代碼實例
PHP對XML提供了的強大的支持。它使用了一個XML的“解析器”,并且為了支持這個解析器,它提供了20(PHP4)個XML的解析函數(shù)。下面是幾個最常用的PHP解析函數(shù)。2008-07-07
使用純php代碼實現(xiàn)頁面?zhèn)戊o態(tài)的方法
這篇文章主要介紹了使用純php代碼實現(xiàn)頁面?zhèn)戊o態(tài)的方法,涉及php服務器預定義變量及正則匹配的相關(guān)使用技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-07-07

