Syntax error, unexpected ‘class’ (T_CLASS) on line 1 after upgrade to php 5.6.4

An error about something on line 1 that is actually on a later position means that PHP doesn’t recognize your line endings.

There are three ways to encode a line ending, and PHP understands only two of them:

  1. LF, or \n, Line Feed, U+000A
  2. CR, or \r, Carriage Return, U+000D
  3. CRLF, or \r\n, the combination of the first and the second

LF is the default on systems like UNIX, Linux, and Mac OS X (since 2001).
CRLF is the default in Windows, inherited from CP/M. Just LF works on Windows too nowadays, there is no need to use CRLF anymore.
CR was the default in Classic Mac OS until 2001.

PHP doesn’t understand 2., CR only, which is understandable, because no one is using that anymore. Well, almost no one. There are still some editors out there that not only allow that obsolete line ending encoding, they don’t even warn their users when they are using it.

Set your editor to use LF only, and you are safe. Unfortunately, the WordPress Coding Standards are silent about this.

Leave a Comment