PHP Parse error on laminas-diactoros

Recenty I was updating some code on my Laravel app and I managed to get it working perfectly on local, no error messages whatsoever, so I decided to upload it to the test server.

When I did, this laminas-diactoros package started giving this error message:

PHP Parse error: syntax error, unexpected ‘fn’ (T_STRING), expecting :: (T_PAAMAYIM_NEKUDOTAYIM) in /route/to/MyProject/vendor/laminas/laminas-diactoros/src/functions/marshal_headers_from_sapi.php on line 29

After some research I learned that this is because in php7.4 fn is a reserved word, so I then did composer require laminas/laminas-diactoros to see if updating the package would make it change syntax and work allright. It wont update further than 2.17 and in that version it still uses fn. I don’t know what else to see or to do. I’m using laravel 6.20.44, php 7.4 and apache2 If you need any more information just ask and I’ll try to answer quick, but this is literally everything I can think of that could be failing.

I’m not really using that library in the code I changed but it is required for other classes of my project.

Hello and welcome to our forums! :smiley:

The syntax is correct because laminas-diactoros uses here the arrow functions of PHP.

Please recheck if you really use version 7.4 of PHP. And please keep in mind that there may be different versions between CLI and your application. (Laravel with version 6.4 also runs with older PHP versions.)

(Duplication of: php 7.4 - PHP Parse error: syntax error, unexpected 'fn' (T_STRING), expecting :: (T_PAAMAYIM_NEKUDOTAYIM) on laminas-diactoros dependency class on Laravel - Stack Overflow)

I’ve checked multiple times the version of everything, including php, laravel and apache. CLI and app both use php7.4, so I don’t know why this error is still showing when it shouldn’t.

[Edit] I just checked with “composer -vvv about” and this is the output:

Reading ./composer.json
Loading config file ./composer.json
Checked CA file /etc/ssl/certs/ca-certificates.crt: valid
Executing command (/var/www/CSP): git branch --no-color --no-abbrev -v
Cannot create cache directory /home/administrador/.composer/cache/repo/https---repo.packagist.org/, or directory is not writable. Proceeding without cache
Cannot create cache directory /home/administrador/.composer/cache/files/, or directory is not writable. Proceeding without cache
Failed to initialize global composer: Composer could not find the config file: /home/administrador/.composer/composer.json
To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section
Reading /var/www/CSP/vendor/composer/installed.json
Running 1.9.1 (2019-11-01 17:20:17) with PHP 7.4.33 on Linux / 4.15.0-213-generic
Composer - Dependency Manager for PHP
Composer is a dependency manager tracking local dependencies of your projects and libraries.
See https://getcomposer.org/ for more information.

So i’m now certain that I’m using the correct php version. Could there be any other issues?

This only says that the version for CLI is correct but not for your application. See: PHP: phpinfo - Manual