动态调用静态变量(数组) [英] Dynamically call a static variable (array)
本文介绍了动态调用静态变量(数组)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我今天的问题。我正在建造一个简单的模板引擎(为乐趣)。基本的想法是,我有一个标签像这样{blog:content},我在一个方法和动作中断。问题是当我想动态调用静态变量时,得到以下错误。
Here's my question for today. I'm building (for fun) a simple templating engine. The basic idea is that I have a tag like this {blog:content} and I break it in a method and a action. The problem is when I want to call a static variable dynamically, I get the following error .
Parse error: parse error, expecting `','' or `';''
代码:
$class = 'Blog';
$action = 'content';
echo $class::$template[$action];
$ template是我的类中的一个公共静态变量
$template is a public static variable(array) inside my class, and is the one I want to retreive.
推荐答案
class Blog {
public static $template = array('content' => 'doodle');
}
Blog::$template['content'] = 'bubble';
$class = 'Blog';
$action = 'content';
$values = get_class_vars($class);
echo $values['template'][$action];
将输出'bubble'
Will output 'bubble'
这篇关于动态调用静态变量(数组)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文