bcit-ci / CodeIgniter

Open Source PHP Framework (originally from EllisLab)
https://codeigniter.com/
MIT License
18.27k stars 7.6k forks source link

Support for PHP 8.3 #6278

Open yasinuddowla opened 7 months ago

yasinuddowla commented 7 months ago

I wanted to use PHP 8.3 with CI 3.1.13

I've installed PHP 8.3 and it gives the following error.

A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_URI::$config is deprecated
Filename: core/URI.php
Line Number: 102
Backtrace:
  File: /Users/yasinuddowla/sites/dana/portal/public/admin.php
  Line: 299
  Function: require_once
jafjaf commented 7 months ago

Codeigniter 3.1.13 don't support PHP >8.2 (yet), you can however update on your own using these changes

If you instead would like an updated repo with PHP 8.2 support see;

otengkwame commented 7 months ago

I am extending a copy of CodeIgniter 3 that works with PHP 8.3 from here: https://github.com/sylynder/webby, https://github.com/sylynder/engine. I am also borrowing some concepts from CodeIgniter 4

putuardiworks commented 6 months ago

@jafjaf, I would like to ask: with the current CodeIgniter v3.1.13, what is the latest stable PHP version that works out-of-the-box?

mariolucasdev commented 6 months ago

@jafjaf, I would like to ask: with the current CodeIgniter v3.1.13, what is the latest stable PHP version that works out-of-the-box?

currently i have 2 projects using the Codeigniter version 3.1.13 running with php 8.2.

jafjaf commented 6 months ago

@jafjaf, I would like to ask: with the current CodeIgniter v3.1.13, what is the latest stable PHP version that works out-of-the-box?

A fresh install of Codeigniter 3 supports PHP version up to and including 8.1. If you're going to start a new project it's better to use Codeigniter 4, however if you're already using Codeigniter 3 and need PHP support above 8.1 you can implement the changes mentioned above.

I'm also running multiple projects using PHP 8.3 and Codeigniter 3 (with PHP >8.2) changes implemented. More specifically these changes

putuardiworks commented 6 months ago

I didn't expect to get a response this fast. Wow, the community is still great 🥳

@mariolucasdev Do you run CodeIgniter v3.1.13 with PHP 8.2 without making any changes to the system?

@jafjaf So, it is safe to use PHP 8.1? And if I want to upgrade to PHP 8.2 or higher, then I need to make the changes you mentioned? I am still working on a CodeIgniter 3 project, so I need to know which is the latest PHP version that is safe to upgrade to.

jafjaf commented 6 months ago

I didn't expect to get a response this fast. Wow, the community is still great 🥳

@mariolucasdev Do you run CodeIgniter v3.1.13 with PHP 8.2 without making any changes to the system?

@jafjaf So, it is safe to use PHP 8.1? And if I want to upgrade to PHP 8.2 or higher, then I need to make the changes you mentioned? I am still working on a CodeIgniter 3 project, so I need to know which is the latest PHP version that is safe to upgrade to.

It depends on how you define "safe."

However, the community remains quite active, and there are ongoing efforts to keep CodeIgniter 3 viable with updates and patches.

Supporting PHP versions for CodeIgniter 3

poodle123 commented 5 months ago

Pocketarc Fork already works with PHP 8.3 without any issues. You just have to adapt your own code where needed:

https://github.com/pocketarc/codeigniter

jafjaf commented 5 months ago

Pocketarc Fork already works with PHP 8.3 without any issues. You just have to adapt your own code where needed:

https://github.com/pocketarc/codeigniter

Quoting jamieburchell below from #6173

The releases from this fork appear to be based on the develop branch and from scanning the commits, include functionality changes. The develop branch is quite a bit different to the last released version.

IMO it would be better to cherry-pick and apply specific fixes to the latest actual release/master if you want to keep as close as possible to the last official 3.1.13 release.

vvp3 commented 5 months ago

Ty for your effor tfirst of all !

Second, I am not a senior so I would not want to do some mistakes, but do it step by step with some help if possilble. Please tell me if following closely the changes here : https://github.com/bcit-ci/CodeIgniter/compare/master...ib3ltd:CodeIgniter:master will help me get to 8.2 at least if not even 8.3

Also, how should I best test the changes ?

  1. install phpstan and run it to point me the errors and fix them ?
  2. or apply the changes above directly and after that run phpstan for more checks ? I never used phpstan in CI to check errors hence me asking dumb q.

Furthermore, in the official 8.1 and 3.13 I have no issues with the code. Is there a way to have in every changed file something like #if php ver = 8.1 .. have this code and if php ver = 8.2 (8.3) have this one ? I do not want to move far away from the official 8.1 + 3.13 so that if there are problems I can revert easy to 8.1

Thank you !

jafjaf commented 5 months ago

Ty for your effor tfirst of all !

Second, I am not a senior so I would not want to do some mistakes, but do it step by step with some help if possilble. Please tell me if following closely the changes here : master...ib3ltd:CodeIgniter:master will help me get to 8.2 at least if not even 8.3

Also, how should I best test the changes ?

1. install phpstan and run it to point me the errors and fix them ?

2. or apply the changes above directly and after that run phpstan for more checks ? I never used phpstan in CI to check errors hence me asking dumb q.

Furthermore, in the official 8.1 and 3.13 I have no issues with the code. Is there a way to have in every changed file something like #if php ver = 8.1 .. have this code and if php ver = 8.2 (8.3) have this one ? I do not want to move far away from the official 8.1 + 3.13 so that if there are problems I can revert easy to 8.1

Thank you !

I'm running with those exact changes in multiple projects without issues.

You don't have to go out of your way to test the changes, every commit to the branch is tested and backwards compatible, see here.

Don't overcomplicate the changes, you're only creating more work for yourself if in case you introduce bugs to the system files.

If you don't want to move away from the official release, have faith on the maintainer(s) to introduce support for PHP +8.2 and wait.

vvp3 commented 5 months ago

@jafjaf appreciate your answer but I am not very savy in moving in and out of commits.

Besides system and application folder and their files, is there any other folder I should check for modifications ? If I apply those modifications to the files prior to moving to 8.2 (will it crash CI or parts of it ?) ? "every commit to the branch is tested and backwards compatible, " >> or this answers exactly my question :)

Do I also need to modify many of my models, views, controllers manually too ?

ps. Besides here I didn't find anythink regarding mantainer(s) to intrpduce support fpr 8.2+ so the wiat would be in vain.

jafjaf commented 5 months ago

@jafjaf appreciate your answer but I am not very savy in moving in and out of commits.

Besides system and application folder and their files, is there any other folder I should check for modifications ? If I apply those modifications to the files prior to moving to 8.2 (will it crash CI or parts of it ?) ? "every commit to the branch is tested and backwards compatible, " >> or this answers exactly my question :)

Do I also need to modify many of my models, views, controllers manually too ?

ps. Besides here I didn't find anythink regarding mantainer(s) to intrpduce support fpr 8.2+ so the wiat would be in vain.

You can view all files changed here. If you follow the changes carefully it should be fine.

All changes are compatible with PHP 5 and above.

"If I apply those modifications to the files prior to moving to 8.2 (will it crash CI or parts of it ?) ?" Are you suggesting to implement all the changes straight to production? Don't, Always test before with multiple versions to ensure compatibility.

"Do I also need to modify many of my models, views, controllers manually too ?" Depends on how your code looks, if you're using deprecated functions you have to update them as well.

If the changes scare you that much you can always migrate to Codeigniter 4, which have support for PHP +8

vvp3 commented 5 months ago

Codeigniter 3.1.13 don't support PHP >8.2 (yet), you can however update on your own using these changes

If you instead would like an updated repo with PHP 8.2 support see;

* https://github.com/ib3ltd/CodeIgniter/tree/master

* https://github.com/pocketarc/codeigniter

The first link is what I needed. Applying those changes to the system files made it work but some small errors in the login page - I am sure it is only becasue dynamic deprecated and I must input it in those classes as well.

Is this #[AllowDynamicProperties] causing any issue as I did not see it in developer branch (there are some modifications here I wouldn't put as they are over my head and I don't think I need them)

I am in 8.2 now. Will the changes from the master branch be enough for 8.3 ? Did you test it ?

Ty again for your patience and answers !

jafjaf commented 5 months ago

@vvp3 i'm using 8.2 in production and 8.3 in testing environments without issues. You can read more about AllowDynamicProperties here.

It's not in the main devlop branch because it haven't been merged yet.

Tampa commented 4 months ago

Is it even necessary to set this at all? Usually the issue comes from the fact properties are added to a class that doesn't have a property for it to begin with, but nothing stops you from just adding the property and leaving it empty until the code requires it. I have a few libraries that utilize dynamic properties and I did just that, adding properties to the classes and so far I can't see any adverse effects of that. It's a bit silly, but I suspect it has some security implications to not allow randomly adding things to classes that were not meant to be there in the first place.

daveherman71 commented 4 months ago

It's necessary as we don't always know what the properties are so we can't pre-define them. Consider, for example, the following code from the CI_Controller class constructor (system\core\Controller.php)

// Assign all the class objects that were instantiated by the
// bootstrap file (CodeIgniter.php) to local class variables
// so that CI can run as one big super object.

foreach (is_loaded() as $var => $class)
{
    $this->$var =& load_class($class);
}

or the following from the CI_Loader class (system\core\Loader.php)

// This allows anything loaded using $this->load (views, files, etc.)
// to become accessible from within the Controller and Model functions.
$_ci_CI =& get_instance();
foreach (get_object_vars($_ci_CI) as $_ci_key => $_ci_var)
{
    if ( ! isset($this->$_ci_key))
    {
        $this->$_ci_key =& $_ci_CI->$_ci_key;
    }
}
kenjis commented 4 months ago

@Tampa It is not necessary to be able to add random properties as you say. A particular controller class should know all about its own properties. Yes, having unintended properties might be a security issue. At least, it is not a good practice. But CI3 users do not seem to care about it.