首页> 开发问题 >后端问题 后端问题
Fatal error: Namespace declaration statement has to be the very first statement or after any declare call in the script in
作者:小萝卜 2019-12-10 【 其它 】 浏览 1944
简介学习php的命名空间,直接把手册的代码粘贴过来,却报错了:Fatal error: Namespace declaration statement has to be the very first statement or after any declare call in the script in
学习php的命名空间,直接把手册的代码粘贴过来,却报错了:Fatal error: Namespace declaration statement has to be the very first statement or after any declare call in the script in
代码如下:
<?php
namespace my\name; // 参考 "定义命名空间" 小节
class MyClass {}
function myfunction() {}
const MYCONST = 1;
$a = new MyClass;
$c = new \my\name\MyClass; // 参考 "全局空间" 小节
$a = strlen('hi'); // 参考 "使用命名空间:后备全局函数/常量" 小节
$d = namespace\MYCONST; // 参考 "namespace操作符和__NAMESPACE__常量" 小节
$d = __NAMESPACE__ . '\MYCONST';
echo constant($d); // 参考 "命名空间和动态语言特征" 小节
解决办法:
将页面转为utp-8无dom格式就OK了。以notepad++为例:
很赞哦! (0)
相关文章
- laravel通过composer安装报错了The 'https://repo.packagist.org/p/laravel/laravel.json' file could not be downloaded: failed to open stream
- 网站打不开错误提示:ERR_CONTENT_DECODING_FAILED
- MySQL: unrecognized service错误解决办法
- 错误400-The request sent by the client was syntactically incorrect
- MYSQL5.7版本sql_mode=only_full_group_by报错解决方案
- windows下mysql中文乱码, 配置解决方法
- TP6报错致命错误: Cannot use object of type stdClass as array
- [vs code] 运行go包提示:Code is already running!
- tp3.2插入数据时SQLSTATE[HY000]: General error
- 语法解析错误: syntax error, unexpected 'unset' (T_UNSET)