zendframework / zend-expressive-skeleton

Begin developing PSR-7 middleware applications in seconds!
BSD 3-Clause "New" or "Revised" License
136 stars 90 forks source link

PHP 7.2 - Parse error: syntax error, unexpected 'const' (T_CONST), expecting variable (T_VARIABLE) #249

Closed brock0124 closed 6 years ago

brock0124 commented 6 years ago

Parse error: syntax error, unexpected 'const' (T_CONST), expecting variable (T_VARIABLE) in /var/www/vendor/zendframework/zend-expressive-fastroute/src/FastRouteRouter.php on line 51


Get this error after fresh clone of zend-expressive-skeleton:3.0. I am running PHP 7.2 on a scotchbox. I have tried several different versions of PHP, several different vagrant boxes, and editing the configuration files in apache. I have removed all of the files in the repository and replaced it with a zend expressive 2 project and it loaded just fine. I have also spun up a local PHP server and the page loaded just fine. Sorry if this issue doesn't belong here, but I have tried everything on the vagrant side that I can think of, I felt the issue has to lie within the code.

Code to reproduce the issue

A fresh clone of of zend-expressive-skeleton:3.0

Expected results

The Zend Expressive home page template.

Actual results

Parse error: syntax error, unexpected 'const' (T_CONST), expecting variable (T_VARIABLE) in /var/www/vendor/zendframework/zend-expressive-fastroute/src/FastRouteRouter.php on line 51

michalbundyra commented 6 years ago

@brock0124 This is the wrong repository for that issue - it should be reported in https://github.com/zendframework/zend-expressive-fastroute

I checked that line and we have there:

    public const CACHE_TEMPLATE = <<< 'EOT'
<?php
return %s;
EOT;

Here is simplified class with just this lines: https://3v4l.org/Po5A4 and as you can see we are getting that error only on PHP 5.6 and 7.0, definitely not on PHP 7.2.

Are you sure you are using PHP 7.2? I can see that scotchbox is using PHP 7.0 in free version and 7.2 in pro version (paid): https://github.com/scotch-io/scotch-box#scotch-box-35 What version are you using?

PHP 7.2 is fine. Expressive requires at least PHP 7.1, can't work on PHP 7.0.

brock0124 commented 6 years ago

scotchbox Thank you for the reply and pointing in me in the right direction. Regarding the PHP version, I have updated it myself. Attached is a screenshot of the PHP version that is hosting the site in the scotchbox.

It's also worth noting I tried using Zend Router and got a very similar error, just tailored to Zend Router class and line number.

I can currently only test in IE 8 due to other browsers forcing HTTPS. Could that be an issue?

Ocramius commented 6 years ago

Careful about that: the CLI and the CGI version of PHP are likely different

On Sun, 1 Apr 2018, 04:12 brock0124, notifications@github.com wrote:

[image: scotchbox] https://user-images.githubusercontent.com/25236863/38169155-09de2a7e-3528-11e8-9e36-d12825fc928a.PNG Thank you for the reply and pointing in me in the right direction. Regarding the PHP version, I have updated it myself. Attached is a screenshot of the PHP version that is hosting the site in the scotchbox.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/zendframework/zend-expressive-skeleton/issues/249#issuecomment-377737641, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJakCIpTPZ1T0Uj205daYWEm1klULfPks5tkDd_gaJpZM4TCgXU .

brock0124 commented 6 years ago

@Ocramius Thank you for your reply. You were correct. When running phpinfo() it told me I was running PHP 7.0 while the command line told me otherwise.

sudo a2dismod php7.0 sudo a2enmod php7.1 sudo service apache2 restart

The code above resolved my issue.