m9dfukc/deepl-alfred-workflow

Os X 10.11 PHP 5.5 issue "Arrays are not allowed in class constants"

ngdot opened this issue · 8 comments

ngdot commented

Hi, just installed your workflow and tried to translate a simple word like "hello", but nothing happens... Here is the debug output:

[2017-10-20 13:02:32][ERROR: input.scriptfilter] Code 255: Fatal error: Arrays are not allowed in class constants in /Users/nicolas/Library/Application Support/Alfred 3/Alfred.alfredpreferences/workflows/user.workflow.1CD96169-6161-4552-8F6F-6167079FACCD/vendor/chriskonnertz/deeply/src/ChrisKonnertz/DeepLy/DeepLy.php on line 43

[2017-10-20 13:02:32][ERROR: input.scriptfilter] JSON error: JSON text did not start with array or object and option to allow fragments not set. in JSON:
Fatal error: Arrays are not allowed in class constants in /Users/nicolas/Library/Application Support/Alfred 3/Alfred.alfredpreferences/workflows/user.workflow.1CD96169-6161-4552-8F6F-6167079FACCD/vendor/chriskonnertz/deeply/src/ChrisKonnertz/DeepLy/DeepLy.php on line 43

Any idea?

Hmm, strange ... give me some time I'll investigate that error.

Can you give me some more insights about which version of Alfred you are using, which version of macOs and which version of php is installed?

Thanks

Hi,

sorry I'm not able to reproduce this error without further details about your setup.

I'll let this issue stay open for now. If anybody else stumbles about this, please provide some information about your setup and I'll have another look!

ngdot commented

Hi, I'm using OS X El Capitan 10.11.6 with PHP 5.6.27 and Alfred 3.5.1.

Hello,

are you absolutely sure that it is PHP 5.6.27? Maybe you have two installations of PHP, one of them being older? "Arrays are not allowed in class constants" is a message that I would expect from PHP 5.5, but not from PHP 5.6 (or higher). Here is a demonstration: http://sandbox.onlinephpfunctions.com/code/d50f416563c2b5cfa163f2f242f520ab54762a46
(click on "execute" to run the code, then choose one of the 5.5.x versions and execute it again)

Unfortunately OS X 10.11 still comes with php 5.5 as default. Alfred 3 uses the version of php provided under /usr/bin/php. Either you replace this binary with a more actual php >= 5.6 or you use the "External Script" functionality of Alfred:

bildschirmfoto 2017-10-23 um 20 03 41

I'll update the README with macOS 10.12 as a minimum requirement.

@chriskonnertz thanks for the hint!

I am on Mac OS with php 5.5 installed as a default. I had the same issue.
I am new to Alfred, so I had no idea where the workflows src folder is, as mentioned above by m9dfkc.

I solved it by

  • installing php 7.0 with curl -s http://php-osx.liip.ch/install.sh | bash -s 7.0. I then copied the path to php7 from the output. On my machine its /usr/local/php5-7.0.27-20180201-135220/bin/php.

  • imported the Deepl Translate.alfredworkflow downloaded from this repo into Alfred.

  • went into the directory /Users/username-here/Library/Application Support/Alfred 3/Alfred.alfredpreferences/workflows/user.workflow.[xxx].

  • created file run.php:

<?php
  $query = trim($argv[1]);

  require_once( __DIR__ . '/deepl.php' );

  // DE, EN, FR, ES, IT, NL, PL are available
  // or use > {LANG_CODE} to force the translation language

  $default_language = 'DE';
  $deepl = new DeeplTranslate($default_language);

  echo $deepl->translate($query);
?> 

In the alfred preferences for the plugin, I clicked on "dl", then changed it to Language: /bin/bash and Script: /usr/local/php5-7.0.27-20180201-135220/bin/php -f run.php "{query}".

Now everything works like a charm.