samrap/acf-fluent

unexpected 'default' (T_DEFAULT), expecting identifier (T_STRING)

pskigen opened this issue · 6 comments

I have installed acf-fluent by running the suggested command in my Wordpress website's theme directory:

composer require samrap/acf-fluent

I then included my composer dependencies by requiring the vendor/autoload.php.

After doing the above and attempting to replicate the following example:

$heading = Acf::field('heading') ->default(get_the_title()) ->escape() ->get();

I receive the error:

Parse error: syntax error, unexpected 'default' (T_DEFAULT), expecting identifier (T_STRING) in {path_to_my_theme}/vendor/samrap/acf-fluent/src/Fluent/Builder.php on line 124

I don't think this should have an impact on the issue, but I am using Wordpress 4.7.3, the latest version of ACF Pro and the theme I am developing is based on the Roots Sage base theme (https://github.com/roots/sage).

Perhaps I am doing something wrong, but I have tried including acf-fluent a few different ways and seem to get the same error every time.

I look forward to using your interface in the future, and thanks in advance!

Sorry for the late response. Thank you for trying out ACF Fluent! I also build all of my WordPress sites off of Sage, so I can assure you it's not an issue there. What PHP version are you using? default is a reserved keyword in PHP (used in switch statements), but as of PHP 7.0 it allowed as "property, constant, and method names of classes, interfaces and traits" (See: List of Keywords).

So, I'm guessing you have a PHP version less than 7.0 and installed ACF Fluent using Composer's --ignore-platform-reqs flag. Can you confirm what PHP version you're using?

Not a problem! I should have mentioned that I am also running Wordpress on Google App Engine (and using the dev_appserver for my local development). Google App Engine runs on PHP version 5.5.34 (https://cloud.google.com/appengine/docs/standard/php/runtime). Based on what you're saying, it sounds like that would be the issue.

Using the standard environment, I don't believe Google allows a different PHP version. Does this mean I will be unable to use your interface until App Engine moves to PHP 7? Or do you have any thoughts on a workaround?

That's really a bummer that Google would have its users on a PHP version that's not even supported by PHP anymore. Unfortunately, I can't think of a workaround in your case. I built this out to support PHP >= 7.0 and I don't have plans to change that. I do have some changes coming to 0.3 that may add some flexibility when it comes to defining your own builder methods, but until then you will need to look into upgrading your PHP version or changing your hosting to a more modern environment.

I found this post on Stack Overflow which seems like it may have a solution for using PHP 7 with Google app engine flexible environment. Not sure what flexible environment is or if it costs extra, but it seems to be a solution.

It is quite frustrating that they haven't kept up with the latest PHP version, especially with PHP dropping support for their current one. Unfortunately, at the firm where I work, we use App Engine for all of our Wordpress sites, so finding a different environment is not really an option at the moment.

The extra research is much appreciated! I don't believe a flexible environment will work for our current dev workflow, but I will do some research in that direction and will let you know if I have any success.

Thank you for the helpful answers!

No problem. I hope you get a chance to use the package. If you use it in the future, let me know what you think!