致命错误:未捕获错误:函数名称必须是php / class-style-generator.php中的字符串

问题描述 投票:0回答:1

我在两个网站上遇到以下错误:

致命错误:未捕获错误:函数名称必须是/home/lanesra2/public_html/wp-content/themes/Lanesra/framework/php/class-style-generator.php:123中的字符串堆栈跟踪:#0 / home / lanesra2 /public_html/wp-includes/class-wp-hook.php(286):

我已经多年没有登录这些网站了,你可以看到它们都建立在WordPress上。任何可以修复它的潜在变化?

这也是代码:

{
            foreach($this->rules as $rule)
            {

                $rule['value'] = str_replace('{{AVIA_BASE_URL}}', AVIA_BASE_URL, $rule['value']);
                $rule['value'] = preg_replace('/(http|https):\/\//', '//', $rule['value']);

                //check if a executing method was passed, if not simply put the string together based on the key and value array
                if(isset($rule['key']) && method_exists($this, $rule['key']) && $rule['value'] != "")
                {
                    $this->output .= $this->$rule['key']($rule)."\n";
                }
                else if($rule['value'] != "")
                {
                    $this->output .= $rule['elements']."{\n".$rule['key'].":".$rule['value'].";\n}\n\n";
                }

            }
        }
php wordpress fatal-error
1个回答
0
投票

检查变量is a string,不仅仅是它被设置,而且具体地说它也是一个字符串。

if(is_string($rule['key']) && method_exists($this, $rule['key']) && $rule['value'] != "")

Alternative:

写入略短,少一个参数。无论如何,这会强制值为字符串;这取决于您的代码库,如果这是您的需要。

if(method_exists($this, (string)$rule['key']) && $rule['value'] != "")

Please be aware that this answer does not solve the issue that sometimes your function is dealing with non-strings as potential methods.

© www.soinside.com 2019 - 2024. All rights reserved.