奇怪的意外T_STRING错误

问题描述:

在当前的Symfony2项目中,我有一个奇怪的PHP错误:

I have a weird PHP error in a current Symfony2 project:

unexpected T_STRING in /blahblah/Foo/BarBundle/Entity/User.php on line 1

这是一个非常标准的错误,通常与一对不匹配的或"有关.

This is a pretty standard error, usually linked to a mismatched pair of " or '.

但这是User.php文件的代码

But here is the code of the file User.php

<?php
namespace Foo\BarBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="fos_user")
 * @ORM\Entity(repositoryClass="Foo\BarBundle\Entity\UserRepository")
 */
class User extends \FOS\UserBundle\Entity\User
{
    // classic user entity

第<?php行是第1行.没有引号,而且奇怪的是,这个错误仅出现在我的登台服务器上:在具有本地代码副本的2个开发机器上,它的行为与预期相同,没有错误或警告. 该文件是正确的文件,缓存已清空.我认为这可能是编码错误,但事实并非如此.我也想到了命名空间问题,但是服务器上的PHP版本正确(5.3.16)

The line <?php is line #1. There is no quotes, and the weird thing comes from the fact that this error only appear on my staging server: on 2 development machines with local copies of the code, it behaves as expected with no error or warning. The file is the correct one, the cache was emptied. I thought that it might be an encoding error but it does not seem to be this. I also thought of namespace issues, but the PHP version on the server is correct (5.3.16)

您是否知道此错误可能是由什么引起的,或者我可以从哪个方向进行搜索?预先感谢.

Do you have any idea what this error can stem from, or in which direction I could search ? Thanks in advance.

我处理过的大多数编码约定严格要求使用LF("Unix风格",'\x0A')行结尾脚本.无论谁设法用CRLF提交代码,或者,天哪,CR都必须忍受皇家的痛苦. )

Most coding conventions that I worked with strictly require using LF ('Unix style', '\x0A') line endings in the scripts. And whoever managed to submit code with CRLF or, god forbid, CR had to endure a royal share of pain. )

这似乎没什么大不了的,但是它可以节省您寻找怪异错误的时间-例如在这种情况下.

It may seem not such a big deal, yet it can save you hours of searching for a weird error - such as in this case.