【问题标题】:Fatal error: Can't use function return value in write context in [closed]致命错误:无法在 [关闭] 的写入上下文中使用函数返回值
【发布时间】:2016-09-15 14:16:54
【问题描述】:

我遇到了这个错误,我无法理解它。

确切的错误信息是:

function kdrusha_theme_create_page() {
    require_once(get_template_directory().= '/inc/pages/kdrusha-settings.php');
}

add_menu_page("KD Rusha Options", 'KD Rusha', 'manage_options', 'kdrusha-options', 'kdrusha_theme_create_page','',99);

【问题讨论】:

  • 为什么里面有=

标签: php function wordpress custom-wordpress-pages


【解决方案1】:

你需要把你的函数返回到某个变量中:

function kdrusha_theme_create_page() {
    $template = get_template_directory();
    require_once($template.'/inc/pages/kdrusha-settings.php');
}

【讨论】:

  • 现在让我看到其他错误(add_menu_page("KD Rusha Options", 'KD Rusha', 'manage_options', 'kdrusha-options', 'kdrusha_theme_create_page','',99);)
【解决方案2】:

问题是您使用的是.=

something .= something_else

是简写

something = something . something_else

但是您的something 是一个函数调用,分配给函数调用通常没有意义(例外是它返回引用时)。

您应该只使用.,它将其参数连接起来并返回结果而不将其分配给任何地方。

require_once(get_template_directory() . '/inc/pages/kdrusha-settings.php');

【讨论】:

    猜你喜欢
    • 2011-08-07
    • 2012-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-03
    • 1970-01-01
    相关资源
    最近更新 更多