Welcome Guest, Not a member yet? Register   Sign In
Poll: Would you consider upgrading to PHP 8.0?
You do not have permission to vote in this poll.
Yes
89.66%
26 89.66%
No
10.34%
3 10.34%
Total 29 vote(s) 100%
* You voted for this item. [Show Results]

Surprised to see codeigniter 3.x running successfull with PHP 8.0 as well.
#8

(01-14-2021, 04:28 PM)CINewb Wrote: Today I installed PHP8 and tried it with our CodeIgniter 3 project.

I found 2 issues:

1) We had a controller class called Attribute which it doesn't like.  Perhaps this is a reserved word in PHP8.

2) More serious - flash data doesn't seem to clear.  Once you have a piece of flash data set, for example "Your changes were saved", it continues to persist on every page load thereafter.   I tracked this down to \system\libraries\Session\Session.php Lines 418 to 423:

Code:
// Hacky, but 'old' will (implicitly) always be less than time() ;)
// DO NOT move this above the 'new' check!
elseif ($value < $current_time)
{
    unset($_SESSION[$key], $_SESSION['__ci_vars'][$key]);
}

Looks like in PHP7 "old" was < time(), whereas in PHP 8 it isn't.  I propose changing this to:

Code:
// Hacky, but 'old' will (implicitly) always be less than time() ;)
// DO NOT move this above the 'new' check!
elseif ($value === 'old' || $value < $current_time)
{
    unset($_SESSION[$key], $_SESSION['__ci_vars'][$key]);
}


Indeed.

I'm guessing the logic was to allow "temporary" variables to store an expiry time when they expire and flash messages to expire straight away and avoiding a dual check. 

PHP8 Changes the behaviour of comparing strings to numbers.

https://wiki.php.net/rfc/string_to_number_comparison


In PHP 7.4 and Below "Old" == <Numeric> would equal True and "Old" < any numeric value would respectively equal true.
This behaviour has now been changed.

So far this has been the only bug I have found. 

Another Gotcha that doesen't affect CI but affects a lot of legacy code I look after is that the charming "STFU Operator" now doesen't STFU.
$variable = @$array['entry']; Now throws an error rather than containing "null" gaaa.
Reply


Messages In This Thread
RE: Surprised to see codeigniter 3.x running successfull with PHP 8.0 as well. - by unplugged - 01-15-2021, 05:31 PM



Theme © iAndrew 2016 - Forum software by © MyBB