Search code examples
phpcoding-stylenewlinegit-commit

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


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?


Solution

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