index.php
require_once('smarty/Smarty.class.php');
$Smarty = new Smarty();
function do_something() {
global $Smarty;
echo "where is smarty?"
var_dump($Smarty);
$ObjSmarty->assign("teams_list", $teams_list);
}
get_active_teams();没有转储和错误分配..。
require_once('smarty/Smarty.class.php');
$Smarty = new Smarty();
function do_something() {
global $Smarty;
echo "where is smarty?"
var_dump($GLOBALS);
var_dump($GLOBALS["Smarty"]);
}
get_active_teams();“全球转储”显示了智能,而当我转储$globals时,“智能”就没有了。怎么回事。
我没有课是因为这个问题吗?
如何在不使用声明类的情况下分配给php函数中加载的智能对象?
发布于 2012-03-22 09:03:18
你在什么地方调用do_something函数了吗?也许你可以这样做:
function do_something($Smarty) {
// ... Do something with smarty here...
}
do_something($Smarty);发布于 2012-03-22 09:05:41
使用全局变量不是一个好主意,为什么不将$Smarty作为函数参数传递呢?
function foo($smarty) {
var_dump($smarty);
}
foo($smarty);https://stackoverflow.com/questions/9817722
复制相似问题