【发布时间】:2023-03-30 20:34:01
【问题描述】:
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 = 新索引; $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();
【问题讨论】: