致命错误:无法重新声明发生在同一行
我已经与这个错误作斗争有一段时间了。错误出现在函数中的某个地方,我现在有 php 告诉我它不能在同一行上重新声明变量......奇怪。任何帮助都会很棒。
致命错误:无法重新声明 bp_block_admin_init()(以前 声明于 /home/bp-member-login-redirect/bp-member-login-redirect-loader.php:31) 在 /home/bp-member-login-redirect/bp-member-login-redirect-loader.php 第 31 行
第 29-31
// make sure buddypress is installed
function bp_block_admin_init() {
require_once( dirname( __FILE__ ) . '/bp-member-login-redirect-core.php' );
}
行,实际调用该函数的行(无论代码中是否包含这些行,我都会收到错误:
if ( defined( 'BP_VERSION' ) ) {
bp_block_admin_init();
} else {
add_action( 'bp_init', 'bp_block_admin_init' );
}
I have been fighting with this error for a while. The error is somewhere in the function I now have php telling me it can't redeclare a variable on the same line... strange. Any help would be great.
Fatal error: Cannot redeclare
bp_block_admin_init() (previously
declared in
/home/bp-member-login-redirect/bp-member-login-redirect-loader.php:31)
in
/home/bp-member-login-redirect/bp-member-login-redirect-loader.php
on line 31
lines 29-31
// make sure buddypress is installed
function bp_block_admin_init() {
require_once( dirname( __FILE__ ) . '/bp-member-login-redirect-core.php' );
}
the lines actually calling the function (i get the error with or without these lines in the code:
if ( defined( 'BP_VERSION' ) ) {
bp_block_admin_init();
} else {
add_action( 'bp_init', 'bp_block_admin_init' );
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
确保使用 require_once 来确保不会双重加载 bp-member-login-redirect-loader.php 文件。
Make sure you use require_once to ensure you're not double loading the bp-member-login-redirect-loader.php file.
问题出在 WordPress 函数
register_activation_hook()
上,该函数在加载插件时被调用。就我而言,该文件是在没有加载 WordPress 的情况下包含的。一旦我删除了这些功能,我就不再收到错误了。The problem was with the WordPress function
register_activation_hook()
which is called when a plugin is loaded. In my case, the file was being included without WordPress loading. Once I removed the functions I no longer got an error.看起来
bp_block_admin_init
被定义了两次。这段代码出现在什么文件中?另一个文件是否多次require
-ing 或include
-ing 该文件?It looks like
bp_block_admin_init
is being defined twice. In what file does this code appear? Is another filerequire
-ing orinclude
-ing this file multiple times?您很可能多次包含
bp-member-login-redirect-loader.php
。例如,以下内容足以重现您的问题:test.php
test2.php
Most likely you're including
bp-member-login-redirect-loader.php
more than once. For example, the following is sufficient to reproduce your problem:test.php
test2.php
请检查
bp_block_admin_init()
函数是否已经存在。Please check it whether the function
bp_block_admin_init()
is already exists or not.