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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With