1

I'm getting a syntax error when enabling modules. This is happening intermittently and it isn't specific to any module in particular, which is making it impossible for me to track down. Here is the error I'm receiving today:

Parse error: syntax error, unexpected end of file in sites/all/modules/contrib/headerimage/headerimage.module on line 821

Line 821 is the very last line of the file, and the syntax looks fine to me. When I get a similar error when enabling modules, it's always complaining about the last line. There are never any missing brackets. I've disabled any custom modules I wrote thinking that it could be my code causing this, but I've had no success.

I was wondering if anyone has run into this, if they have any suggestions, or possibly a method to troubleshoot this.

-- EDIT --

I was able to resolve the syntax errors for this particular module (headerimage). I had to delete the very last line in two of the files and re-add them manually. They were closing brackets "}".

I'm not convinced that this is the correct fix. Maybe it's some kind of encoding issue? Any thoughts?

closed as too broad by kiamlaluno May 7 '16 at 23:30

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

2

I figured out what this was. It wasn't necessarily related to Drupal or PHP syntax, but the answer might save someone else some stress.

I had VMWare Fusion on my Mac running a Linux VM with Apache/MySQL/PHP server. The webroot for Apache was a shared directory on my host machine which contained my Drupal install. I did this so I can have the benefit of a Linux web server while being able to edit my code locally on my host.

This works when serving up the site, but whenever I used Drush on the VM to install a module, there was always a hidden line appended to the module's files that Vi didn't pick up, which is why the syntax error was always on the last line. I'm assuming it had to do with the hgfs filesystem used for sharing between my host and the VM.

Once I removed the VM sharing and modified everything on the VM itself, all of my problems went away. Downloading modules with Drush no longer produces these syntax errors.

Here is a related thread on the Drush issue queue where people are having similar issues.

https://drupal.org/node/1948962

Thanks to those who gave their feedback. --richard

1

This is a parse error which occurs when php is still looking for something and reaches the end of the file without finding it. It could be a quote or bracket which is unclosed, and php is still treating the file contents as a part of the quote.

Yes line 821 is the last line of the file. Php is just telling you it was unexpected.

Errors like this are not intermittent, but you might have to do some work to find how to reproduce it. Once you do that, you can start eliminating modules to try to find the source.

Good luck.

0

It could be as simple as removing the last closing PHP tag (?>), if one exists, at the end of the file(s). Generally no files should end with a closing PHP tag, although they should have a starting tag (<?php) at the very beginning.

  • 2
    Actually, contrary to many answers in stack overflow, the closing tag will not generate this error. The reason for omitting the closing tag in php scripts is to prevent the accidental output of unintended white space, which will generate 'Headers already sent' errors. See the manual. – Triskelion Mar 5 '13 at 20:11
  • Yea, that's true. I stand corrected. Thanks for the update/refresh. – enzipher Mar 5 '13 at 20:27
  • Thanks for the input. That was the first thing that I checked for since I remember reading that in Drupal's best practices. – Richard Robinson Mar 5 '13 at 20:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.