【发布时间】:2021-02-11 20:38:06
【问题描述】:
我在 wordpress 中开发了一个自定义插件,它工作正常,但突然出现异常错误,如下所示
Fatal error: Namespace declaration statement has to be the very first statement or after any declare call in the script in /public_html/demo2/wp-content/plugins/my-plugin-custom/inc/admin/Settings.php on line 7
这是第 7 行的内容
<?php
/**
* @package My Custom Plugin
*/
namespace Inc\admin;
class Settings {
public function register() {
add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
}
}
任何人都可以帮助我解决这个问题到底发生了什么我真的很困惑
【问题讨论】:
-
如果命名空间没有问题,那么您可以尝试在
<?php之后插入namespace Inc\admin;[可能是第二行] -
看看有没有leading space。
-
@AkhtarujjamanShuvo 你能把这个作为对我有用的答案吗