Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weird unexpected T_STRING error

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 '.

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

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.

like image 351
ClemKeirua Avatar asked Sep 03 '12 16:09

ClemKeirua


People also ask

What is T_String?

T_String is the common parse error associated with the creation of PHP files. This problem is observed when an apostrophe sign is added in between a code that has been delimited with apostrophes, generating huge conflict with the PHP document.

How do you solve an unexpected syntax error?

A parse error: syntax error, unexpected appears when the PHP interpreter detects a missing element. Most of the time, it is caused by a missing curly bracket “}”. To solve this, it will require you to scan the entire file to find the source of the error.

What does syntax error unexpected mean?

Syntax Error – This error is caused by an error in the PHP structure when a character is missing or added that shouldn't be there. Unexpected – This means the code is missing a character and PHP reaches the end of the file without finding what it's looking for.


1 Answers

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.

like image 109
raina77ow Avatar answered Sep 20 '22 15:09

raina77ow