先识别标签后计算的模板思路-PHP源码
传统模板引擎的思路是:计算模板变量->设置模板变量(assign)->整合模板并显示页面。现在想要实现这样的效果:识别模板变量->计算模板变量->整合并显示页面。
这里提供一种思路,利用PHP的魔术方法 __call 来实现。
$method_name($args[0]); } else { $r = $this->$method_name(); } return $r; } /** * hello world * @return string */ public function get_test($op) { return 'hello world!'; } }
main(); //声明页面标签 $test = $tpl->test(); ?>
PHP之友评论