PHP类中的范围问题:PHP中的类范围问题
为什么这样工作?
class index extends Application
{
function ShowPage()
{
$smarty = new Smarty(); // construct class
$smarty->assign('name', 'Ned'); // then call a method of class
$smarty->display('index.tpl');
}
}
$ index_instance = new index; $ index_instance-> ShowPage();
但这不起作用?
class index extends Application
{
function ShowPage()
{
$smarty->assign('name', 'Ned');
$smarty->display('index.tpl');
}
}
$index_instance = new index;
$smarty = new Smarty();
$index_instance->ShowPage();
'global'不是来自前一个范围的变量,而是来自全局范围。 – NullUserException 2010-07-21 16:18:48
好,我纠正了误导评论。 – Charles 2010-07-21 16:23:35
谢谢你的作品! – 2010-07-21 16:45:11