首页 > 解决方案 > Wordpress:“警告:非法字符串偏移”在多个地方

问题描述

希望你们能在这里帮助我。在我的 WordPress 安装中这些问题发生了什么,请参阅错误和引用的代码块。

错误:

Warning: Illegal string offset 'domain' in /home/customer/www/xxxxxxxx.xxx/public_html/wp-includes/l10n.php on line 583

Warning: Illegal string offset 'context' in /home/customer/www/xxxxxxxx.xxx/public_html/wp-includes/l10n.php on line 587

Warning: Illegal string offset 'singular' in /home/customer/www/xxxxxxxx.xxx/public_html/wp-includes/l10n.php on line 588

Warning: Illegal string offset 'plural' in /home/customer/www/xxxxxxxx.xxx/public_html/wp-includes/l10n.php on line 588

Warning: Illegal string offset 'context' in /home/customer/www/xxxxxxxx.xxx/public_html/wp-includes/l10n.php on line 588

Warning: Illegal string offset 'domain' in /home/customer/www/xxxxxxxx.xxx/public_html/wp-includes/l10n.php on line 583

Warning: Illegal string offset 'context' in /home/customer/www/xxxxxxxx.xxx/public_html/wp-includes/l10n.php on line 587

Warning: Illegal string offset 'singular' in /home/customer/www/xxxxxxxx.xxx/public_html/wp-includes/l10n.php on line 588

Warning: Illegal string offset 'plural' in /home/customer/www/xxxxxxxx.xxx/public_html/wp-includes/l10n.php on line 588

Warning: Illegal string offset 'context' in /home/customer/www/xxxxxxxx.xxx/public_html/wp-includes/l10n.php on line 588

代码:

function translate_nooped_plural( $nooped_plural, $count, $domain = 'default' ) {
    if ( $nooped_plural['domain'] ) {
        $domain = $nooped_plural['domain'];
    }

    if ( $nooped_plural['context'] ) {
        return _nx( $nooped_plural['singular'], $nooped_plural['plural'], $count, $nooped_plural['context'], $domain );
    } else {
        return _n( $nooped_plural['singular'], $nooped_plural['plural'], $count, $domain );
    }
}

标签: phpwordpresserror-handlingsyntax-error

解决方案


Warning: Illegal string offset 'something'消息意味着您正在尝试访问的值,$someVar['something']但它不存在。

为避免这种情况,您应该始终使用isset($someVar['something'])检查给定变量中是否存在(或不存在)索引。


推荐阅读