seboettg / citeproc-php

Full-featured CSL 1.0.1 processor for PHP
MIT License
75 stars 39 forks source link

PHP Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead) #42

Closed shajamansoor closed 6 years ago

shajamansoor commented 6 years ago

Am using below code, but it shows error.

`<?php include "vendor/autoload.php"; use Seboettg\CiteProc\StyleSheet; use Seboettg\CiteProc\CiteProc;

$data = file_get_contents("metadata.json"); $style = StyleSheet::loadStyleSheet("din-1505-2"); $citeProc = new CiteProc($style); echo $citeProc->render(json_decode($data), "bibliography");`

Error : PHP Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead) in /var/www/html/bib/vendor/seboettg/citeproc-php/src/Seboettg/CiteProc/Util/NumberHelper.php on line 97

How can i fix this issue?

seboettg commented 6 years ago

Hi! I guess this is error is caused by an old PHP version. Please determine which PHP version you are use.

<?php
phpinfo();

On line 97 in Seboettg\CiteProc\Util\NumberHelper you find the expression if (isset(self::ROMAN_DIGITS[$char])) ROMAN_DIGITS is an array defined as constant. This is supported since PHP 5.6+. Older PHP versions just support boolean, int, float and string.

I suspect that you're using an older PHP version than 5.6

shajamansoor commented 6 years ago

Hi Dude,

Am using PHP Version 5.6.11-1ubuntu3.4 in my local machine.

seboettg commented 6 years ago

Did you test it with your web server? Sure that you're using also the right php module for your web server? You can configure Ubuntu to use different PHP binaries in command line interface and web server.

seboettg commented 6 years ago

@shajamansoor: Does it work now?

bozana commented 6 years ago

Hi @seboettg, I am using 5.6.30+dfsg-0+deb8u1 and I get the same error message. My editor shows me also this line as syntax error, thus shouldn't there be rather something like if (array_key_exists($char, self::ROMAN_DIGITS[$char])) ? I wonder how come you and the others do not experience this... Could it be that you are using PHP 7?

seboettg commented 6 years ago

Yes, usually I use PHP 7. My local environment allows to switch between different PHP versions. I had tried with PHP 5.6 just now and your described issue occurs also in my case. Since I have switched to PHPUnit 6 (which needs at least PHP version 7) I was running all tests with PHP 7.0 and 7.1. Thus, this error slipped through the net.

I'm going to release a bugfix asap.

Thanks a lot for your contribution!

seboettg commented 6 years ago

please try out the new release 2.0.2

bozana commented 6 years ago

👍 Thanks a lot! The release 2.0.2 works for me :-)))

seboettg commented 6 years ago

Great!