web-push-libs / web-push-php

Web Push library for PHP
MIT License
1.69k stars 295 forks source link

Parse error: syntax error, unexpected '|', expecting ';' or '{' in vendor/web-token/jwt-key-mgmt/JWKFactory.php on line 156 #353

Closed JeyjooMilano closed 6 months ago

JeyjooMilano commented 2 years ago

Setup

Please provide the following details, the more info you can provide the better.

Please check that you have installed and enabled these PHP extensions :

following enables: gmp, mbstring, curl, openssl

Please select any browsers that you are experiencing problems with: All browsers tested in Chrome and firefox (latest versions)

Problem

I want to generate a VAPID key set using the web-push-php package.

I get the error: Parse error: syntax error, unexpected '|', expecting ';' or '{' in .../push/vendor/web-token/jwt-key-mgmt/JWKFactory.php on line 156

Expected

Expected to return VAPID key

Features Used

VAPID Support

Example / Reproduce Case

Here is my code:

require_once '../push/vendor/autoload.php'; use Minishlink\WebPush\VAPID; $keyset = VAPID::createVapidKeys(); echo $keyset["publicKey"]; file_put_contents("vapid.json", json_encode($keyset));

Other

It is not liking the |. Line 156 is: public static function createFromJsonObject(string $value): JWK|JWKSet

Any ideas? Thanks

snitchyuk commented 1 year ago

I know this is an old issue, but as I came across it as well I thought I'd reply with the resolution in case someone else has the problem.

The error above is caused when using the most up to date version of web-token/jwt-key-mgmt on PHP 7. The most up to date version is only compatible with PHP 8. Therefore to resolve the problem I downgraded to a lower version of web-token/jwt-key-mgmt which works with PHP 7 and now everything is working perfectly.