f3-factory / fatfree-core

Fat-Free Framework core library
GNU General Public License v3.0
206 stars 88 forks source link

Fatal error with php 7.4RC3 #286

Closed kumy closed 5 years ago

kumy commented 5 years ago

A fatal error is returned when loading f3 with php 7.4RC3.

Fatal error: Unparenthesized `a ? b : c ? d : e` is deprecated. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)`

Step to reproduce

$ docker run --rm -it php:7.4.0RC3-cli-alpine sh
/ # mkdir f3; cd f3

/f3 # cat <<'EOF' > index.php
<?php
require __DIR__.'/vendor/autoload.php';
$f3 = \Base::instance();
$f3->route('/', function (){echo 'Hello';});
$f3->run();
EOF

/f3 # php index.php 
Fatal error: Unparenthesized `a ? b : c ? d : e` is deprecated. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)`

/f3 # php --version
PHP 7.4.0RC3 (cli) (built: Oct  4 2019 21:53:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0-dev, Copyright (c) Zend Technologies

Notes No line number is returned by php, but seems to happens there https://github.com/bcosca/fatfree-core/blob/master/base.php#L993-L995.

It don't know the legacy php <= 7.3 behavior. How should it be fixed?

(isset($prop) ? $prop : $frac) ? strlen($frac)-2 : 0
or
isset($prop) ? $prop : ($frac ? strlen($frac)-2 : 0)
Rayne commented 5 years ago

I thought that we already fixed another PHP 7.4-RC issue but was not able to find one. Which F3 version are you using? I'll have a look.

The relevant section in the manual: Ternary Operator.

kumy commented 5 years ago

I'm on 3.6.5

$ composer show|grep fatfree
bcosca/fatfree-core                3.6.5              A powerful yet easy-to-use PHP micro-framework designed to help you build dynamic and robust Web applications - fast!
kumy commented 5 years ago

According to the Example #4 Non-obvious Ternary Behaviour from your link, the fix shoud be: (isset($prop) ? $prop : $frac) ? strlen($frac)-2 : 0

Would you like a PR?

Rayne commented 5 years ago

The bug is no longer present in the master branch. The bug is already fixed but is not part of a stable release: https://github.com/bcosca/fatfree/issues/1142

kumy commented 5 years ago

Ho you're right, just discovered the parenthesis in master branch! BTW I naivelly have put the parenthesis the other way, but I've not tested anything.

Sorry to make you loose your time.