Dynamically call a static variable (array)

后端 未结 5 1186
情深已故
情深已故 2021-01-03 07:57

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 an

5条回答
  •  被撕碎了的回忆
    2021-01-03 08:10

    What about get_class_vars ?

    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];
    

    Will output 'bubble'

提交回复
热议问题