Seldaek / monolog

Sends your logs to files, sockets, inboxes, databases and various web services

Home Page:https://seldaek.github.io/monolog/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PHP Parse error: syntax error, unexpected ‘|', expecting variable (T_VARIABLE)

jacquie-engbrecht opened this issue · comments

PHP Parse error: syntax error, unexpected ‘|', expecting variable (T_VARIABLE) in vendor/psr/log/src/LoggerInterface.php on line 30

Diff from v. 2.3.2 to 2.3.4 in LoggerInterface.php

30c30
<     public function emergency($message, array $context = array());
---
>     public function emergency(string|\Stringable $message, array $context = []): void;

Diff from psr/log v. 1.0.1 and v. 2.0 in composer.json

14c14
<         “php”: “>=5.3.0"
---
>         “php”: “>=8.0.0"
18c18
<             “Psr\\Log\\“: “Psr/Log/”
---
>             “Psr\\Log\\“: “src”
23c23
<             “dev-master”: “1.1.x-dev”
---
>             “dev-master”: “2.0.x-dev”

I'm working with php version 7.4.9, so it appears that the update to using psr/log version 2.0/3.0 which requires php 8.0 is breaking things. Is there a way around this without updating my version of php?

Run composer on PHP 7.4.9 without using --ignore-platform-reqs, and composer will keep using psr/log 1.0

I have the same problem.
My hoster can only use 7.3.
After I did "composer update", I got a new monolog update but also psr:

 Upgrading psr/log (1.1.3 => 3.0.0)

which requires php 8...

my solution for now is I locked monolog in composer.json to "2.2.0". (before "^2.2")

@millsoft which version of PHP have you used to run composer update ?

If you must stay compatible with PHP 7.3, there are only 2 valid ways to run composer:

Otherwise, if you run your composer update on PHP 8, composer has no reason to restrict dependencies to versions compatible with PHP 7.3, as it tries to resolve them for PHP 8 instead.

commented

You could explicitly require a version of psr/log in composer.json like 1.1.4

there is no reason for monolog to do that. It would the force all users of monolog to use that particular psr/log version (which they will complain about). The current version constraint is working perfectly fine when you use composer properly.

For laravel, delete the vendor folder, and the composer.lock file and then run composer install. it worked for me

commented

@microsoftjulius Worked like a champ!! I had upgraded to PHP 8 and Laravel 8 (latest as 2 weeks ago). my program wouldn't work quite right after the upgrade. (it is integrated into eBay Shopping API for 4 years with Laravel 6 and PHP 7.4

After I upgraded that is when the problems began. thanks for sharing this. I had completely forgotten to do this. it reset everything. I backed up my Vendor folder and composer.json and composer.lock just in case. Wow oh wow, thank you.

Thank you so much @glet

"require": { [...] "psr/log": "^1", [...] }

did the trick

"psr/log": "^1"

Worked for me. Thanks

For laravel, delete the vendor folder, and the composer.lock file and then run composer install. it worked for me

This method works for me. Thanks

Run composer on PHP 7.4.9 without using --ignore-platform-reqs, and composer will keep using psr/log 1.0

Thanks Man, it worked.

@glet Thanks your solution worked for me.

commented

"php" artisan key:generate
PHP Parse error: syntax error, unexpected '|', expecting variable (T_VARIABLE) in C:\xampp\htdocs\laravel-gym-main\vendor\nunomaduro\termwind\src\Functions.php on line 17

can somebody help, what's wrong with this?

"php" artisan key:generate PHP Parse error: syntax error, unexpected '|', expecting variable (T_VARIABLE) in C:\xampp\htdocs\laravel-gym-main\vendor\nunomaduro\termwind\src\Functions.php on line 17

can somebody help, what's wrong with this?

try:
composer update nunomaduro/termwind

If the issue persists after updating the package, you can try manually editing the Functions.php file to remove any syntax errors. Here's what you can do:

Open the Functions.php file located in vendor/nunomaduro/termwind/src/ folder.
Look for the line with the syntax error mentioned in the error message (in this case, it's line 17).
Check the line and see if there are any syntax errors, such as missing semicolons or unmatched parentheses. In your case, it seems to be a problem with the use of | character. You can replace it with a proper variable name.
Save the file and try running the php artisan key:generate command again.

@erjje if you have an issue with the nunomaduro/termwind package, please use their issue tracker (or StackOverflow) instead of commenting on an old issue of the monolog/monolog package.