{$key} or $key?

时间:2020-08-31 作者:Olivia Chen

我在wordpress主题中遇到了这个函数。

function get( $key ) {
        if ( method_exists( $this, \'get_\' . $key ) ) {
            return call_user_func_array( array( $this, \'get_\' . $key ), array() );
        } elseif ( property_exists( $this, $key ) ) {
            return $this->{$key};
        }

        return false;
    }
为什么$this中需要{}大约$key->;{$key}?$this如何->$钥匙不正常?谢谢

1 个回复
最合适的回答,由SO网友:Vicky P 整理而成

当我们在任何变量中使用$时,它就会变成变量变量(variable vars),就像$$name一样

检查变量变量的此引用。

https://www.php.net/manual/en/language.variables.variable.php

在这里$this->$key 将成为变量var,因为它是关于类的公共/私有/受保护变量的。

So{}in$this->{$key} 将设置类的$key vars变量

相关推荐

WordPress破解了5.5 admin-ajax.php

我正在使用WordPress主题和插件的最新版本(5.5)。我还有2个自定义编写的附加组件。我尝试了所有我知道的保护方法。wp-config.php wp admin url和admin nick已更改.htaccess 使残废xmlrpc.php 和wp-config.php已安装Wordfence+2FA登录密码重置被阻止MYSQL名称和密码良好</我被黑了。https://prnt.sc/u13mku 请参见照片wp-admin/admin-ajax.php 和wp-login.php你能给我