Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected 'function": zend-diactoros/src/functions/marshal_headers_from_sapi.php on line 10 #315

Closed
jazty opened this issue Jul 11, 2018 · 23 comments
Labels

Comments

@jazty
Copy link

@jazty jazty commented Jul 11, 2018

Hello
I recently ran into a problem running zend-diactoros 1.8.1 with a Drupal distribution and Acquia Dev Desktop. Downgrading to 1.7.2 got everything working again.

Here's the error:
PHP Parse error: syntax error, unexpected 'function' (T_FUNCTION), expecting identifier (T_STRING) or \\ (T_NS_SEPARATOR) in /Users/name/Sites/devdesktop/website-dev/vendor/zendframework/zend-diactoros/src/functions/marshal_headers_from_sapi.php on line 10

and here's the full stack trace:
`Call Stack:
0.0021 123204 1. {main}() /Applications/DevDesktop/tools/vendor/drush/drush/drush.php:0
0.0047 252652 2. drush_main() /Applications/DevDesktop/tools/vendor/drush/drush/drush.php:12
0.6006 8062072 3. Drush\Boot\BaseBoot->bootstrap_and_dispatch() /Applications/DevDesktop/tools/vendor/drush/drush/includes/preflight.inc:66
0.6088 8068264 4. drush_dispatch() /Applications/DevDesktop/tools/vendor/drush/drush/lib/Drush/Boot/BaseBoot.php:67
0.6122 8071720 5. call_user_func_array:{/Applications/DevDesktop/tools/vendor/drush/drush/includes/command.inc:199}() /Applications/DevDesktop/tools/vendor/drush/drush/includes/command.inc:199
0.6122 8071904 6. drush_command() /Applications/DevDesktop/tools/vendor/drush/drush/includes/command.inc:199
0.6126 8072544 7. _drush_invoke_hooks() /Applications/DevDesktop/tools/vendor/drush/drush/includes/command.inc:231
0.6239 8287916 8. call_user_func_array:{/Applications/DevDesktop/tools/vendor/drush/drush/includes/command.inc:422}() /Applications/DevDesktop/tools/vendor/drush/drush/includes/command.inc:422
0.6239 8288036 9. drush_sql_dump() /Applications/DevDesktop/tools/vendor/drush/drush/includes/command.inc:422
0.6239 8288052 10. drush_sql_bootstrap_further() /Applications/DevDesktop/tools/vendor/drush/drush/commands/sql/sql.drush.inc:251
0.6242 8288072 11. drush_sql_bootstrap_database_configuration() /Applications/DevDesktop/tools/vendor/drush/drush/commands/sql/sql.drush.inc:197
0.6242 8288144 12. drush_bootstrap_max() /Applications/DevDesktop/tools/vendor/drush/drush/commands/sql/sql.drush.inc:186
0.6263 8289020 13. drush_bootstrap_validate() /Applications/DevDesktop/tools/vendor/drush/drush/includes/bootstrap.inc:507
0.6278 8290028 14. Drush\Boot\DrupalBoot->bootstrap_drupal_root_validate() /Applications/DevDesktop/tools/vendor/drush/drush/includes/bootstrap.inc:430
0.6285 8290056 15. drush_drupal_version() /Applications/DevDesktop/tools/vendor/drush/drush/lib/Drush/Boot/DrupalBoot.php:268
0.6291 8290080 16. Drush\Boot\DrupalBoot8->get_version() /Applications/DevDesktop/tools/vendor/drush/drush/includes/drupal.inc:43
0.6291 8290096 17. drush_drupal_load_autoloader() /Applications/DevDesktop/tools/vendor/drush/drush/lib/Drush/Boot/DrupalBoot8.php:40
0.6293 8293152 18. require('/Users/name/Sites/devdesktop/website-dev/docroot/autoload.php') /Applications/DevDesktop/tools/vendor/drush/drush/includes/drupal.inc:17
0.6293 8294472 19. require('/Users/name/Sites/devdesktop/website-dev/vendor/autoload.php') /Users/name/Sites/devdesktop/website-dev/docroot/autoload.php:17
0.6296 8306404 20. ComposerAutoloaderInit3b0e50ed5f365629937fa738e0be1282::getLoader() /Users/name/Sites/devdesktop/website-dev/vendor/autoload.php:7
0.6400 8830052 21. composerRequire3b0e50ed5f365629937fa738e0be1282() /Users/name/Sites/devdesktop/website-dev/vendor/composer/autoload_real.php:56

PHP Parse error: syntax error, unexpected 'function' (T_FUNCTION), expecting identifier (T_STRING) or \ (T_NS_SEPARATOR) in /Users/name/Sites/devdesktop/website-dev/vendor/zendframework/zend-diactoros/src/functions/marshal_headers_from_sapi.php on line 10
PHP Stack trace:
PHP 1. {main}() /Applications/DevDesktop/tools/vendor/drush/drush/drush.php:0
PHP 2. drush_main() /Applications/DevDesktop/tools/vendor/drush/drush/drush.php:12
PHP 3. Drush\Boot\BaseBoot->bootstrap_and_dispatch() /Applications/DevDesktop/tools/vendor/drush/drush/includes/preflight.inc:66
PHP 4. drush_dispatch() /Applications/DevDesktop/tools/vendor/drush/drush/lib/Drush/Boot/BaseBoot.php:67
PHP 5. call_user_func_array:{/Applications/DevDesktop/tools/vendor/drush/drush/includes/command.inc:199}() /Applications/DevDesktop/tools/vendor/drush/drush/includes/command.inc:199
PHP 6. drush_command() /Applications/DevDesktop/tools/vendor/drush/drush/includes/command.inc:199
PHP 7. _drush_invoke_hooks() /Applications/DevDesktop/tools/vendor/drush/drush/includes/command.inc:231
PHP 8. call_user_func_array:{/Applications/DevDesktop/tools/vendor/drush/drush/includes/command.inc:422}() /Applications/DevDesktop/tools/vendor/drush/drush/includes/command.inc:422
PHP 9. drush_sql_dump() /Applications/DevDesktop/tools/vendor/drush/drush/includes/command.inc:422
PHP 10. drush_sql_bootstrap_further() /Applications/DevDesktop/tools/vendor/drush/drush/commands/sql/sql.drush.inc:251
PHP 11. drush_sql_bootstrap_database_configuration() /Applications/DevDesktop/tools/vendor/drush/drush/commands/sql/sql.drush.inc:197
PHP 12. drush_bootstrap_max() /Applications/DevDesktop/tools/vendor/drush/drush/commands/sql/sql.drush.inc:186
PHP 13. drush_bootstrap_validate() /Applications/DevDesktop/tools/vendor/drush/drush/includes/bootstrap.inc:507
PHP 14. Drush\Boot\DrupalBoot->bootstrap_drupal_root_validate() /Applications/DevDesktop/tools/vendor/drush/drush/includes/bootstrap.inc:430
PHP 15. drush_drupal_version() /Applications/DevDesktop/tools/vendor/drush/drush/lib/Drush/Boot/DrupalBoot.php:268
PHP 16. Drush\Boot\DrupalBoot8->get_version() /Applications/DevDesktop/tools/vendor/drush/drush/includes/drupal.inc:43
PHP 17. drush_drupal_load_autoloader() /Applications/DevDesktop/tools/vendor/drush/drush/lib/Drush/Boot/DrupalBoot8.php:40
PHP 18. require() /Applications/DevDesktop/tools/vendor/drush/drush/includes/drupal.inc:17
PHP 19. require() /Users/name/Sites/devdesktop/website-dev/docroot/autoload.php:17
PHP 20. ComposerAutoloaderInit3b0e50ed5f365629937fa738e0be1282::getLoader() /Users/name/Sites/devdesktop/website-dev/vendor/autoload.php:7
PHP 21. composerRequire3b0e50ed5f365629937fa738e0be1282() /Users/name/Sites/devdesktop/website-dev/vendor/composer/autoload_real.php:56
Drush command terminated abnormally due to an unrecoverable error. [error]
Error: syntax error, unexpected 'function' (T_FUNCTION), expecting
identifier (T_STRING) or \ (T_NS_SEPARATOR) in
/Users/name/Sites/devdesktop/website-dev/vendor/zendframework/zend-diactoros/src/functions/marshal_headers_from_sapi.php,
line 10 [0.6 sec, 8.42 MB]`

@weierophinney

This comment has been minimized.

Copy link
Member

@weierophinney weierophinney commented Jul 11, 2018

That line reads:

use function array_key_exists;

Function importing is allowed by PHP since version 5.6:

All versions of PHP that support namespaces support three kinds of aliasing or importing: aliasing a class name, aliasing an interface name, and aliasing a namespace name. PHP 5.6+ also allows aliasing or importing function and constant names.

Diactoros has only supported PHP 5.6+ since version 1.5.0, released 2017-08-22 (just shy of a year ago).

My guess is that one of the following is true:

  • Your composer.json includes a platform.php setting that includes a 5.6 or later version constraint (which would allow installing the package, even if the PHP version on your system is lower).
  • You used the --ignore-platform-reqs CLI flag when running composer install.

The point is: the syntax is correct, for the versions of PHP we support.

You can downgrade in one of the following ways:

  • Set the version constraint for the zendframework/zend-diactoros package to 1.4.1 (the last version to support PHP 5.5).
  • Remove the platform.php setting in your project package, and then run composer update.
  • Run composer update and/or composer install without the --ignore-platform-reqs flag.

Either way, this is not something we can or will fix.

@samsonasik

This comment has been minimized.

Copy link
Contributor

@samsonasik samsonasik commented Jul 16, 2018

Very strange. I got same error when I try in aws with php version 5.6.30 as shown below:

ubuntu@server:~$  /usr/local/zend/bin/php -v

PHP 5.6.30 (cli) (built: Jan 22 2017 10:10:16) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend Extension Manager v8.5.0, Copyright (c) 2003-2015, by Zend Technologies
    - with Zend Data Cache v8.5.0, Copyright (c) 2004-2015, by Zend Technologies [loaded] [licensed] [disabled]
    - with Zend Job Queue v8.5.0, Copyright (c) 2004-2015, by Zend Technologies [loaded] [licensed] [enabled]
    - with Zend Session Clustering v8.5.0, Copyright (c) 2004-2015, by Zend Technologies [loaded] [licensed] [disabled]
    - with Zend Utils v8.5.0, Copyright (c) 2004-2015, by Zend Technologies [loaded] [licensed] [enabled]
    - with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies [loaded] [licensed] [enabled]
    - with Zend Code Tracing v8.5.0, Copyright (c) 2009-2015, by Zend Technologies [loaded] [licensed] [enabled]
    - with Zend Server Z-Ray v8.5.0, Copyright (c) 1999-2015, by Zend Technologies [loaded] [licensed] [enabled]
    - with Zend Monitor v8.5.0, Copyright (c) 1999-2015, by Zend Technologies [loaded] [licensed] [disabled]
    - with Zend Debugger v8.5.0, Copyright (c) 1999-2015, by Zend Technologies [loaded] [licensed] [enabled]
    - with Zend Page Cache v8.5.0, Copyright (c) 2004-2015, by Zend Technologies [loaded] [licensed] [disabled]
@weierophinney

This comment has been minimized.

Copy link
Member

@weierophinney weierophinney commented Jul 16, 2018

@samsonasik I just tested the unit tests from PHP 5.6.36, and checked to ensure that the tests actually hit that function; they do, and with no errors.

I wonder if there was an issue sometime during the 5.6 series? Either way, we can verify that the code runs on latest 5.6, which means the issue lies with specific versions of PHP.

@samsonasik

This comment has been minimized.

Copy link
Contributor

@samsonasik samsonasik commented Jul 16, 2018

@weierophinney It is probably the php issue 5.6.30 issue. The error is happen during "composer install", I run composer update locally and committed composer.lock, in aws server, it read composer.lock and run composer install, and show above error.

rolled back to zend-diactoros ~1.7.2 (which already require php 5.6) fixes the issue.

@phillipgong

This comment has been minimized.

Copy link

@phillipgong phillipgong commented Jul 23, 2018

Strange. My website is running on php 7.1.12 with zend-diactoros 1.8.1 version but still I have the same issue. With zend-diactoros 1.7.2, I'm getting these errors.

`PHP Parse error: syntax error, unexpected ':', expecting ';' or '{' in /Users/name/Sites/devdesktop/site-dev/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationRegistry.php on line 50

Parse error: syntax error, unexpected ':', expecting ';' or '{' in /Users/name/Sites/devdesktop/site-dev/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationRegistry.php on line 50
Drush command terminated abnormally due to an unrecoverable error. [error]
Error: syntax error, unexpected ':', expecting ';' or '{' in /Users/name/Sites/devdesktop/site-dev/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationRegistry.php, line 50`

@weierophinney

This comment has been minimized.

Copy link
Member

@weierophinney weierophinney commented Jul 23, 2018

@phillipgong The parse errors you show are from Doctrine's AnnotationRegistry class, not any Diactoros classes or functions...

@shindaseishin

This comment has been minimized.

Copy link

@shindaseishin shindaseishin commented Jul 24, 2018

@phillipgong posted the wrong error message. He was getting the Diactoros error messages in the original error report until I got him to downgrade Diactoros using composer. He then started getting the AnnotationRegistry error that he accidentally posted here.

edit: spelling

@weierophinney

This comment has been minimized.

Copy link
Member

@weierophinney weierophinney commented Jul 24, 2018

That's fine, but I need the actual error message observed.

BTW, I've not been able to reproduce this at all. I've tried with each of PHP 5.6.36, 7.0.30, 7.1.17, and 7.2.5, and Travis itself is running 5.6.32, 7.0.31, 7.1.11, and 7.2.8 without errors. Locally, I've run the unit tests, as well as a bare Expressive skeleton; both of these would exercise that function during normal processing.

With the inability to reproduce the issue, I need a LOT more information from those experiencing it:

  • Which PHP version are you using?
  • Which SAPI are you using? (e.g., CLI, php-fpm, mod_php)
  • How is the code being exercised? (e.g., are you using ServerRequestFactory? If so, how are you calling it?)
  • What are the exact errors you see reported?

The original report indicated this was done with Drupal and the Acquia Dev Desktop; what PHP versions are they using? What SAPI? etc.

@theroyal

This comment has been minimized.

Copy link

@theroyal theroyal commented Jul 26, 2018

I get the same error
when I try to run "Drush" commands
I have Drupal 8 installed by composer
the PHP-CLI is v5.6

@weierophinney

This comment has been minimized.

Copy link
Member

@weierophinney weierophinney commented Jul 26, 2018

@theroyal what is the SPECIFIC PHP version, please? I can then compile and test that version locally so as to determine if it's a PHP issue.

If I'm still unable to reproduce, the common problem has been with folks using Drush, which means it may be doing some parsing of its own.

@jazty

This comment has been minimized.

Copy link
Author

@jazty jazty commented Jul 31, 2018

Ok, figured it out on our end. This applies to anyone who is using Acquia Dev Desktop.
The Drush launcher at /Applications/DevDesktop/tools/drush will use PHP 5.5 if the environment variable isn't set before launching DevDesktop, which is probably 99% of the instances out there.

The quick and dirty way to get things working is to edit /Applications/DevDesktop/tools/drush and change the fallback PHP version to 5.6. The better way would be for Acquia to have their software set the environment variable to match the Drupal site's default version before running Drush. I'll push that suggestion their way.

@hyunpill3

This comment has been minimized.

Copy link

@hyunpill3 hyunpill3 commented Jul 31, 2018

@jazty Great! That is a breakthrough. The errors happened because of devdesktop and your solution works like a charm. Thanks!

@weierophinney

This comment has been minimized.

Copy link
Member

@weierophinney weierophinney commented Jul 31, 2018

Thanks for the update, @jazty ! Glad to know you got it sorted, and thanks for posting here so others who encounter the issue know what to do to resolve it!

@michalsen

This comment has been minimized.

Copy link

@michalsen michalsen commented Aug 3, 2018

@jazty for the closing point of the week.

@samsonasik

This comment has been minimized.

Copy link
Contributor

@samsonasik samsonasik commented Oct 6, 2018

It seems a composer issue event PHP_BINARY path specified at front of composer command, it kept read system's detected 'php' command. I applyed link the system's php to the php 5.6 binary (ln -s command) and it fixes the issue.

@yatinkapur

This comment has been minimized.

Copy link

@yatinkapur yatinkapur commented Feb 7, 2019

@jazty @weierophinney @hyunpill3 could please specify the exact files path + file name where I need to change the PHP version.
My directory paths are bit different. A composer.json file sits at C:\Program Files (x86)\DevDesktop\tools while the another can be found at C:\Program Files (x86)\DevDesktop\tools\vendor\drush\drush.

@ghalenir

This comment has been minimized.

Copy link

@ghalenir ghalenir commented Feb 7, 2019

Ok, figured it out on our end. This applies to anyone who is using Acquia Dev Desktop.
The Drush launcher at /Applications/DevDesktop/tools/drush will use PHP 5.5 if the environment variable isn't set before launching DevDesktop, which is probably 99% of the instances out there.

The quick and dirty way to get things working is to edit /Applications/DevDesktop/tools/drush and change the fallback PHP version to 5.6. The better way would be for Acquia to have their software set the environment variable to match the Drupal site's default version before running Drush. I'll push that suggestion their way.

It worked for me too.

paulsheldrake added a commit to kanopi/pantheon-lightning-headless that referenced this issue Feb 8, 2019
@pkd809

This comment has been minimized.

Copy link

@pkd809 pkd809 commented Sep 21, 2019

Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE) in /home/vagrant/vendor/zendframework/zend-diactoros/src/functions/marshal_uri_from_sapi.php on line 83

Getting the above error when I define senry fucntion.

@weierophinney

This comment has been minimized.

Copy link
Member

@weierophinney weierophinney commented Sep 23, 2019

@pkd809 Please read the thread fully. You're using an unsupported PHP version; Diactoros requires at least PHP 7.1.

@alhevi

This comment has been minimized.

Copy link

@alhevi alhevi commented Dec 2, 2019

Got same error:
php[16283]: PHP Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE) in /var/www/vhosts/panel.example.tld/httpdocs/vendor/zendframework/zend-diactoros/src/functions/marshal_uri_from_sapi.php on line 83

Using PHP 7.3.12

@weierophinney

This comment has been minimized.

Copy link
Member

@weierophinney weierophinney commented Dec 2, 2019

@alhevi You're clearly NOT on PHP 7.3, at least not where you're deploying. How do we know? Because our tests exercise that code for PHP versions 7.1 and up, and no parse errors occur. They will occur on earlier versions.

Double-check the version being used by mod_php or php-fpm where you're deployed.

@alhevi

This comment has been minimized.

Copy link

@alhevi alhevi commented Dec 2, 2019

Well because php infos shows 7.3 is used for everything (and im running on plesk, so it should also use for everthing 7.3) I think it could maybe an ipv6 issue, because on line 83 is "marshalIpv6HostAndPort", but If you say it cloud only because, something is not using 7.3 I will have an deeping look into it

@weierophinney

This comment has been minimized.

Copy link
Member

@weierophinney weierophinney commented Dec 2, 2019

@alhevi The line in question reads:

$marshalIpv6HostAndPort = function (array $server, ?int $port) : array {

The parser error quoted is referencing the ?int, which indicates a nullable integer typehint on a function parameter.

The only reason you'd get a parse error is if you're on a PHP version older than 7.1. Proof: https://3v4l.org/iXelR

It's not uncommon for hosts to have a different PHP version for CLI versus mod_php/php-fpm. Put a script on your server with <?php phpinfo() as the sole contents, access it via a browser, and see what that reports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.