I'm making a new Plugin for CraftCMS, it works fine locally but when I call the services class on our staging server it throws a Syntax Error, Unexpected end of file.

I've installed them both through Composer in the same way, (Symlink in composer.json pointing to local directory.)

I've tried adding "?>" to the end of my PHP file incase that was the issue but didn't resolve. I've also doubled checked all my closing brackets which seem to be fine.

The only difference I can think is maybe PHP version? Locally im on 7.4 and the staging server is 7.2.

Any help would be appreciated.

  • Can you post the file that is causing the error? Hard to tell what's causing the error without seeing the code.
    – MoritzLost
    Nov 2, 2021 at 10:43

1 Answer 1


The error likely indicates some language construct or syntax that is valid in PHP 7.4 but isn't in 7.2 – for example, indented heredoc strings only work in PHP 7.3 and above and would produce the Unexpected end of file error in previous versions.

In general, make sure to test your plugin in your development environment against all PHP versions you intend to support. For a new plugin, I wouldn't bother supporting older PHP versions that aren't supported any more. Right now, PHP 7.3 is close to end-of-life (security support until december 2021), so for a new plugin I would require 7.4.

Make sure to include the minimum supported PHP version in your composer.json so Composer will warn users trying to install the plugin using older versions:

    "require" : {
        "php" : ">=7.4",

See composer.json schema.

For the record, you should update your staging server. PHP 7.2 has been out of security support for a year. Also, you should always try to match environments between development, staging and production as close as possible. Developing on PHP 7.4 and deploying on 7.2 will cause headaches like this that can be easily avoided.

  • 1
    Thank you for this! I've been out of the PHP world for a few years and hadn't realised 7.2 wasn't supported anymore. I'll be sure to update everything to 7.4 going forward and do my best to keep versions consistent. Nov 2, 2021 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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