Home  >  Article  >  Backend Development  >  一个很小疑问

一个很小疑问

WBOY
WBOYOriginal
2016-06-13 10:34:33726browse

一个小小的疑问
在smarty3中,模板目录$template_dir和编译目录$compile_dir都是用protected修饰的,为什么在类外面可以直接访问呢呢??

我把源代码中的protected改成private居然还可以访问,这是为什么呢?

------解决方案--------------------
他不是有这样的定义吗?

PHP code
    public function __get($name)    {        $allowed = array(        'template_dir' => 'getTemplateDir',        'config_dir' => 'getConfigDir',        'plugins_dir' => 'getPluginsDir',        'compile_dir' => 'getCompileDir',        'cache_dir' => 'getCacheDir',        );        if (isset($allowed[$name])) {            return $this->{$allowed[$name]}();        } else {            trigger_error('Undefined property: '. get_class($this) .'::$'. $name, E_USER_NOTICE);        }    }<div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn