PHP: Is there a reason to put a newline at the end of file

Christian Kolb picture Christian Kolb · Mar 29, 2012 · Viewed 9.6k times · Source

When I commit a php file to github I get the message "No newline at end of file".

It's just a warning and I remember, that for any reason it is good to have a newline at the end of a file.

But why? Is it a remnant of long gone times, does it still have advantages or is it even required in php? If yes, for what reason?

Answer

jmoreno picture jmoreno · Mar 29, 2012

It's not required by PHP, but it can cause problems with some diff tools. The warning is a just a warning and can be ignored if desired, but I would recommend following convention and having the last character be a newline.