DeepLcom / deepl-php

Official PHP library for the DeepL language translation API.
MIT License
207 stars 22 forks source link

Getting "syntax error, unexpected ')' in src/Translator.php" when constructing Translator #13

Closed Hardys- closed 1 year ago

Hardys- commented 2 years ago
Docker php:7.4-fpm

I get a syntax error when calling:

$translator = new \DeepL\Translator($authKey);

and if you look into the file deepl-php/src/Translator.php at Line 552 and Line 559 shown as below:

// Line 552, validateAndAppendTexts()
throw new DeepLException(
    'texts parameter must be a non-empty string or array of non-empty strings',
);

// Same as above, Line 559, validateAndAppendTexts()
throw new DeepLException(
    'texts parameter must be a non-empty string or array of non-empty strings',
);

Remove the comma right after the message will fix it :

throw new DeepLException(
    'texts parameter must be a non-empty string or array of non-empty strings'
);

Just in case anyone has the same issue, so I posted it here :)

daniel-jones-deepl commented 1 year ago

Hi @Hardys-, thank you for creating this issue.

I'm surprised that you get this error using PHP 7.4; trailing commas are permitted in function calls since PHP 7.3; 7.3 is the minimum supported version for this library. I wonder if there is something significant about using PHP-FPM. Of course it would be an easy fix as you suggested.

I could not reproduce the problem using the php:7.4-fpm Docker image. Can you please share the error message you get?

Hardys- commented 1 year ago

Sure thing, the message said

Parse error:  syntax error, unexpected ')' in /usr/share/nginx/html/php/vendor/deeplcom/deepl-php/src/Translator.php on line 233

29091670389413_ pic

However, I think there might be some issue with my docker image, I tried to re-build the php: 7.4-fpm and I cannot reproduce the problem either.

Will close this and keep posted if I find something new. Thanks!