CodeIgniter Forums
Deprecated dynamic properties in PHP 8.2 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: General (https://forum.codeigniter.com/forumdisplay.php?fid=1)
+--- Forum: Lounge (https://forum.codeigniter.com/forumdisplay.php?fid=3)
+--- Thread: Deprecated dynamic properties in PHP 8.2 (/showthread.php?tid=82678)

Pages: 1 2


Deprecated dynamic properties in PHP 8.2 - InsiteFX - 08-08-2022

Deprecated dynamic properties in PHP 8.2


RE: Deprecated dynamic properties in PHP 8.2 - sneakyimp - 01-17-2023

Is there any plan to fix this in CI3?

From what I recall, CI uses dynamically assigned properties rampantly. I'm trying to upgrade a site running on PHP 7 (which is EOL as of 2022/11/28) and there are a whole lot of dynamic property deprecation errors. These errors in my case are limited to about 6 classes (at least for the one page i've looked at so far) but I suspect there are more classes with this problem. I created an issue on the ci3 repo. I hope others might go chime in over there.

Also, is this a problem in CI4?


RE: Deprecated dynamic properties in PHP 8.2 - kenjis - 01-17-2023

(01-17-2023, 03:58 PM)sneakyimp Wrote: Also, is this a problem in CI4?

No. v4.2.11 or later fully supports PHP 8.2.
But users' app code may have this issue.


RE: Deprecated dynamic properties in PHP 8.2 - ubeljan - 01-19-2023

(01-17-2023, 03:58 PM)Codeigniter 3 and PHP 8.2To get rid of the error messages you have to change some variables in the system map.
With this changes I could access the database and email libraries without error messages.
Add the public variables to the mentioned files./system/core/URI.php Wrote:
class CI_URI {

    public $config;
   
   
/system/core/Router.php   

class CI_Router {

    public $uri;
   
   
/system/core/Loader.php 
   
class CI_Loader {
   
    public $load;
    public $benchmark;
    public $config;
    public $log;
    public $hooks;
    public $utf8;
    public $uri;
    public $router;
    public $exceptions;
    public $output;
    public $security;
    public $input;
    public $lang; 
   
   
/system/core/Controller.php     
   
class CI_Controller {

    public $benchmark;   
    public $config;
    public $log;   
    public $hooks; 
    public $utf8;   
    public $uri;
    public $router;   
    public $exceptions;   
    public $output;   
    public $security;
    public $input;   
    public $lang; 
    public $db;     
    public $email;

Please correct me when I'm wrong.

Ubel Jan van Wijhe


sneakyimpIs there any plan to fix this in CI3?

From what I recall, CI uses dynamically assigned properties rampantly. I'm trying to upgrade a site running on PHP 7 (which is EOL as of 2022/11/28) and there are a whole lot of dynamic property deprecation errors. These errors in my case are limited to about 6 classes (at least for the one page i've looked at so far) but I  suspect there are more classes with this problem. I created an issue on the ci3 repo. I hope others might go chime in over there.

Also, is this a problem in CI4?



RE: Deprecated dynamic properties in PHP 8.2 - ubeljan - 01-19-2023

I think a better way is to implement  #[\AllowDynamicProperties]

Easier and much shorter.

In all the above mentioned classes add #[\AllowDynamicProperties] above class xxxxxx {

I give you my changes:


/system/core/URI.php

    #[\AllowDynamicProperties]

    class CI_URI {
   
   
/system/core/Router.php   

    #[\AllowDynamicProperties]

    class CI_Router {
   
   
/system/core/Loader.php 

    #[\AllowDynamicProperties]
   
    class CI_Loader {
   
   
/system/core/Controller.php     
   
    #[\AllowDynamicProperties]

    class CI_Controller {   
   
   
/system/core/DB_driver.php   

    #[\AllowDynamicProperties]

    abstract class CI_DB_driver {


RE: Deprecated dynamic properties in PHP 8.2 - superior - 01-19-2023

(08-08-2022, 12:51 PM)InsiteFX Wrote: Deprecated dynamic properties in PHP 8.2

Interesting changes, thanks for the headsup!


RE: Deprecated dynamic properties in PHP 8.2 - sneakyimp - 01-19-2023

(01-19-2023, 06:53 AM)ubeljan Wrote:
(01-17-2023, 03:58 PM)Codeigniter 3 and PHP 8.2To get rid of the error messages you have to change some variables in the system map. With this changes I could access the database and email libraries without error messages.  Add the public variables to the mentioned files./system/core/URI.php Wrote: class CI_URI {

    public $config;
Given the rampant use of dynamic properties that I've seen in CI3's source code, I don't know if adding all of these public object properties is the best approach. Are you sure that you got them all? I expect you haven't. I also think that some of the ways by which CI3 loads libraries may introduce a near-infinite number of new object properties that you have no accounted for.

If you had read the link in the original post of this thread, you would know there are two other ways which would cover all possible dynamic properties, and these would involve a lot less code:
1) implement __get and __set methods to intercept assignment of properties that have not been expressly defined.
2) Add the AllowDynamicProperties attribute in the relevant classes.
Code:
#[\AllowDynamicProperties]



RE: Deprecated dynamic properties in PHP 8.2 - nilo - 01-24-2023

Anyone can hack the core .. is a bad practice !!!  #6
I don't undestand ..
I'm spending a lot of time to try to solve this brutal problem... and only two solution are :
implement __get and __set AND
hack the core ???

I don't want hack the core... probably there is another solution ..
Is it possible that anyone can't release a version with this FIX for PHP V8.2?

It is too strange

is a solution implement _get and _set with hook? 

if someone have a solution please can post this here 
Thank you so much


RE: Deprecated dynamic properties in PHP 8.2 - dexterbrian - 02-16-2023

(01-19-2023, 09:02 AM)ubeljan Wrote: I think a better way is to implement  #[\AllowDynamicProperties]

Easier and much shorter.

In all the above mentioned classes add #[\AllowDynamicProperties] above class xxxxxx {

I give you my changes:


/system/core/URI.php

    #[\AllowDynamicProperties]

    class CI_URI {
   
   
/system/core/Router.php   

    #[\AllowDynamicProperties]

    class CI_Router {
   
   
/system/core/Loader.php 

    #[\AllowDynamicProperties]
   
    class CI_Loader {
   
   
/system/core/Controller.php     
   
    #[\AllowDynamicProperties]

    class CI_Controller {   
   
   
/system/core/DB_driver.php   

    #[\AllowDynamicProperties]

    abstract class CI_DB_driver {

This totally worked for me. Thank you


RE: Deprecated dynamic properties in PHP 8.2 - michaelvuillermoz - 07-14-2023

hello
what is the situation for this problem,
will a core update will be published?