Welcome Guest, Not a member yet? Register   Sign In
Deprecated dynamic properties in PHP 8.2
#1

Deprecated dynamic properties in PHP 8.2
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#2

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?
Reply
#3

(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.
Reply
#4

(This post was last modified: 01-19-2023, 06:54 AM by ubeljan.)

(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?
Reply
#5

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 {
Reply
#6

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

Interesting changes, thanks for the headsup!
Reply
#7

(This post was last modified: 01-19-2023, 02:19 PM by sneakyimp.)

(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]
Reply
#8

(This post was last modified: 01-24-2023, 10:27 AM by nilo.)

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
Reply
#9

(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
Reply
#10

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




Theme © iAndrew 2016 - Forum software by © MyBB