php laravel 错误:命名空间声明语句必须是第一个语句或在脚本中的任何声明调用之后

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46335319/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 03:12:49  来源:igfitidea点击:

laravel error : Namespace declaration statement has to be the very first statement or after any declare call in the script

phplaravellaravel-5.5

提问by Kenneth

After I pull my project in git. I get this error. Its my 1st time to encounter this error.

在我将项目拉入 git 之后。我收到这个错误。这是我第一次遇到这个错误。

the error is:

错误是:

Namespace declaration statement has to be the very first statement or after any declare call in the script

my Model

我的模特

 <?php

namespace App\Models;

the version of my laravel is 5.5. any idea?

我的 Laravel 版本是 5.5。任何的想法?

回答by Gayan

There is an empty space before the <?phptag. Remove it.

<?php标签前有一个空格。去掉它。

<?php

namespace App\Models;

回答by veyselsahin

If problem continue you have to remove bom from file via notepad++

如果问题仍然存在,您必须通过记事本++从文件中删除 bom

回答by ShirleyCC

Also check that your IDE create UTF-8 files (with NO BOM) UTF-8 BOM. For example, in phpStorm Settings / Editor / File Encodings -> Create UTF-8 files: with NO BOM

还要检查您的 IDE 是否创建了 UTF-8 文件(没有 BOM) UTF-8 BOM。例如,在 phpStorm Settings / Editor / File Encodings -> Create UTF-8 files: with NO BOM

回答by Lekia

In some cases, it may be that you're looking at the wrong. Especially in Laravel/Laravel testing, if you move, copy or rename a file. Possibilities are it could be pointing to the old file.

在某些情况下,您可能看错了。特别是在 Laravel/Laravel 测试中,如果您移动、复制或重命名文件。有可能它指向旧文件。