pkoppstein / jm

CLI for streaming JSON
Apache License 2.0
10 stars 0 forks source link

PHP Parse error #1

Closed JonTheoDenseAir closed 1 year ago

JonTheoDenseAir commented 1 year ago

Hello, I've installed as per your instructions (using composer to get json_machine then copying the jm file into /usr/bin + chmod 755) but when I try running a simple command I get an error:

$ jm -h
PHP Parse error:  syntax error, unexpected ':', expecting ')' in /usr/bin/jm on line 290

Info:

$ php --version
PHP 7.4.33 (cli) (built: Feb 22 2023 20:07:47) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.33, Copyright (c), by Zend Technologies

$ uname -a
Linux xxxxxxxxxxxxxxxxxxxx 5.10.0-22-cloud-amd64 #1 SMP Debian 5.10.178-3 (2023-04-22) x86_64 GNU/Linux

Any help appreciated, TIA,

Jon

pkoppstein commented 1 year ago

The jm script has to be able to find the JSON Machine installation. That’s why the installation instructions are as follows:


The simplest way to install "JSON Machine" is usually to run:

composer require halaxa/json-machine

in the user's home directory or in the same directory in which you intend to install the jm script.

To install composer, you could try brew install composer using homebrew. 
See "Additional Documentation" below for further details and alternatives.

If you wish to clone or download the JSON Machine repository instead of installing it using composer, 
then please note that jm will assume it resides in the directory ~/github/json-machine/.
JonTheoDenseAir commented 1 year ago

Those are the instructions I followed, you're saying the following installation is incorrect?:

$ pwd
/home/jtheo
$ ls jm
jm
$ ls vendor/halaxa/json-machine/*
vendor/halaxa/json-machine/CHANGELOG.md  vendor/halaxa/json-machine/Makefile   vendor/halaxa/json-machine/composer.json
vendor/halaxa/json-machine/LICENSE.txt   vendor/halaxa/json-machine/README.md  vendor/halaxa/json-machine/phpunit.xml.dist

vendor/halaxa/json-machine/build:
build-image.sh  composer-lt-7.2.json  composer-update.sh  docker-run.sh  update-changelog.php

vendor/halaxa/json-machine/examples:
guzzleHttp.php  memLeak.php  symfonyHttpClient.php

vendor/halaxa/json-machine/img:
github.png  logo.png  logo.svg  wallpaper.png

vendor/halaxa/json-machine/src:
Exception       Items.php         JsonDecoder  PositionAware.php  StringChunks.php  TokensWithDebugging.php  autoloader.php
FileChunks.php  ItemsOptions.php  Parser.php   StreamChunks.php   Tokens.php        ValidJsonPointers.php

vendor/halaxa/json-machine/test:
JsonMachineTest  bootstrap.php  performance

$ ls composer.*
composer.json  composer.lock
pkoppstein commented 1 year ago

In your original post, you said you moved the jm script into /usr/bin

pkoppstein commented 1 year ago

Looking more closely at line 290, I see that it assumes support for "named arguments", which is a feature that seems to require PHP 8. Since you indicated you're still on PHP 7, that is probably the issue.

If you don't wish to upgrade to PHP 8, the simplest workaround would presumably be to provide the other arguments explicitly:

json_decode(
    string $json,
    ?bool $associative = null,
    int $depth = 512,
    int $flags = 0)
JonTheoDenseAir commented 1 year ago

OK that makes sense, I will see if I can upgrade.

If not I'll try the workaround above.

btw yes I had copied the jm to /usr/bin not sure why now, but have removed and tried running from my home dir with no surprises same result.

JonTheoDenseAir commented 1 year ago

Hi I'll close this ticket as I'm waiting for ops to upgrade. Thanks for your help, much appreciated.