You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Creation of dynamic property CI_URI::$config is deprecated #6192
I have a CI3 site that's been running production on a PHP 7 server. PHP 7 is now EOL so we are migrating the server to PHP 8. It seems to work for 8.0 and 8.1, but in 8.2 dynamic property assignment has been deprecated so a single page load results in tons of warnings. I believe this problem still persists in the very latest CI 3.1.13.
It looks like there's a fairly small number of classes to which CI3 attempts to assign dynamic properties so perhaps this can be quickly fixed to make CI3 compatible with PHP 8.2? I see that supermod InsiteFX posted the ci forum with a semi-helpful post. If I understand correctly, it could be fixed by implementing __get and __set methods or, alternatively, we could use a PHP Attribute for classes to which CI3 assigns dynamic properties.
// this is an attribute
#[\AllowDynamicProperties]
class Post
{
}
$post = newPost();
$post->name = 'Name'; // All fine
Each warning throws an exception with its call stack but that's a LOT of text so I've just included the messages below. There are a lot of messages but it's only referring to about six classes here. It would be helpful to have a complete list of all classes to which CI3 attempts to assign dynamic properties.
Creation of dynamic property CI_URI::$config is deprecated
Creation of dynamic property CI_Router::$uri is deprecated
Creation of dynamic property Home::$benchmark is deprecated
Creation of dynamic property Home::$hooks is deprecated
Creation of dynamic property Home::$config is deprecated
Creation of dynamic property Home::$log is deprecated
Creation of dynamic property Home::$utf8 is deprecated
Creation of dynamic property Home::$uri is deprecated
Creation of dynamic property Home::$exceptions is deprecated
Creation of dynamic property Home::$router is deprecated
Creation of dynamic property Home::$output is deprecated
Creation of dynamic property Home::$security is deprecated
Creation of dynamic property Home::$input is deprecated
Creation of dynamic property Home::$lang is deprecated
Creation of dynamic property Home::$db is deprecated
Creation of dynamic property CI_DB_mysqli_driver::$failover is deprecated
Creation of dynamic property Home::$session is deprecated
Creation of dynamic property Home::$alerts is deprecated
Creation of dynamic property CI_Cache::$file is deprecated
Creation of dynamic property Home::$cache is deprecated
Creation of dynamic property CI_Cache::$dummy is deprecated
Creation of dynamic property Home::$agent is deprecated
Creation of dynamic property CI_Loader::$load is deprecated
Creation of dynamic property CI_Loader::$language is deprecated
Creation of dynamic property CI_Loader::$view_admin_menu is deprecated
Creation of dynamic property CI_Loader::$paywall_routing is deprecated
Creation of dynamic property CI_Loader::$no_index_no_follow is deprecated
Creation of dynamic property CI_Loader::$site_version is deprecated
Creation of dynamic property CI_Loader::$benchmark is deprecated
Creation of dynamic property CI_Loader::$hooks is deprecated
Creation of dynamic property CI_Loader::$config is deprecated
Creation of dynamic property CI_Loader::$log is deprecated
Creation of dynamic property CI_Loader::$utf8 is deprecated
Creation of dynamic property CI_Loader::$uri is deprecated
Creation of dynamic property CI_Loader::$exceptions is deprecated
Creation of dynamic property CI_Loader::$router is deprecated
Creation of dynamic property CI_Loader::$output is deprecated
Creation of dynamic property CI_Loader::$security is deprecated
Creation of dynamic property CI_Loader::$input is deprecated
Creation of dynamic property CI_Loader::$lang is deprecated
Creation of dynamic property CI_Loader::$db is deprecated
Creation of dynamic property CI_Loader::$session is deprecated
Creation of dynamic property CI_Loader::$alerts is deprecated
Creation of dynamic property CI_Loader::$cache is deprecated
Creation of dynamic property CI_Loader::$agent is deprecated
Creation of dynamic property CI_Loader::$typography is deprecated
Creation of dynamic property Home::$typography is deprecated
With the next changes the welcome page appears without errrors.
Add the public statements to the mentioned files.
/system/core/URI.php
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;
If this is a bad idea, please let me know.
I will now import an existing project in the above environment and see what happens.
I will let you know.
Ubel Jan
Reacted by Mantraism, Mahbub Alam Shohag, Faith Musangi, clemens12, Firman and Kachi
A few additions after asking a question to the database and showing the answer.
I give you all my adjustments.
The adjustments in /system/core/Controller.php are coming from my /config/autoload.php file.
The section libraries and model have to be declared in /system/core/Controller.php
I have them commented them.
/system/core/URI.php
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;
// coming from autoload.php libraries and model
public $db; // libraries
public $email; // libraries
public $WorldM; // model
@ubeljan it's good to see what you've suggested here, but I'm not sure adding some collection of public properties to these classes is going to solve the problem in the general sense. I vaguely recall that CI3 assigns a LOT of dynamic properties to the controller. I can think of two other ways that we might fix this, but would like to hear from the CI devs and/or community.
Approach 1: __get and __set methods
Add the $dynamic_properties var and these methods to every class that has dynamic properties set
protected$dynamic_properties = [];
function__set($prop, $val) {
$this->dynamic_properties[$prop] = $val;
}
function__get($prop) {
if (array_key_exists($prop, $this->dynamic_properties)) {
return$this->dynamic_properties[$prop];
} else {
thrownewException("Property $prop does not exist");
}
}
Approach 2: AllowDynamicProperties attribute
Use the PHP AllowDynamicProperties attribute to tell PHP you'd like these classes to permit dynamic attributes:
To be clear, I have often lamented that CI uses undeclared properties so frequently -- IDEs don't know what kind of object you might be referring to, so all the code hinting features are disabled -- I just think one of these two approaches would be a more comprehensive and reasonable solution.
For now I think the shortest way is approach 2.
To implement #[\AllowDynamicProperties] in the classes.
For now I have seen 5 places where to add #[\AllowDynamicProperties] to get a working website.
/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 {
Reacted by sneakyimp, raj4ever, Heri Irawan, colinalbion, Luciano Perez, Shoukat Mirza, Kinjal Shah, Boaz Bechar, braj yadav, Robert Mackie and 6 more
For now I have seen 5 places where to add #[\AllowDynamicProperties] to get a working website.
This is helpful information! I wonder if perhaps @narfbg might sound off on our suggested solution here, and let us know what other classes have dynamic properties?
The described problem in the first post of this issue is already fixed by #6173... It's just in the first PRs if you open the Pull Requests page.
It looks like there's a fairly small number of classes to which CI3 attempts to assign dynamic properties so perhaps this can be quickly fixed to make CI3 compatible with PHP 8.2?
It would be helpful to have a complete list of all classes to which CI3 attempts to assign dynamic properties.
That's why I waited for more incoming issues and pull requests on this matter. And thanks for your list of them. I compared with what we already in the previously mentioned PR and we covered all the cases.
Activity
FIX: Fixes dynamic property deprecation error
zanderwar commentedon Jan 15, 2023
@t1xart SSL is broken on that page and Cloudflare firewall says it is dangerous and blocks my access 🤷
sneakyimp commentedon Jan 17, 2023
I have a CI3 site that's been running production on a PHP 7 server. PHP 7 is now EOL so we are migrating the server to PHP 8. It seems to work for 8.0 and 8.1, but in 8.2 dynamic property assignment has been deprecated so a single page load results in tons of warnings. I believe this problem still persists in the very latest CI 3.1.13.
It looks like there's a fairly small number of classes to which CI3 attempts to assign dynamic properties so perhaps this can be quickly fixed to make CI3 compatible with PHP 8.2? I see that supermod InsiteFX posted the ci forum with a semi-helpful post. If I understand correctly, it could be fixed by implementing
__getand__setmethods or, alternatively, we could use a PHP Attribute for classes to which CI3 assigns dynamic properties.Each warning throws an exception with its call stack but that's a LOT of text so I've just included the messages below. There are a lot of messages but it's only referring to about six classes here. It would be helpful to have a complete list of all classes to which CI3 attempts to assign dynamic properties.
ubeljan commentedon Jan 19, 2023
With the next changes the welcome page appears without errrors.
Add the public statements to the mentioned files.
/system/core/URI.php
class CI_URI {
/system/core/Router.php
class CI_Router {
/system/core/Loader.php
class CI_Loader {
/system/core/Controller.php
class CI_Controller {
If this is a bad idea, please let me know.
I will now import an existing project in the above environment and see what happens.
I will let you know.
Ubel Jan
ubeljan commentedon Jan 19, 2023
A few additions after asking a question to the database and showing the answer.
I give you all my adjustments.
The adjustments in /system/core/Controller.php are coming from my /config/autoload.php file.
The section libraries and model have to be declared in /system/core/Controller.php
I have them commented them.
/system/core/URI.php
class CI_URI {
/system/core/Router.php
class CI_Router {
/system/core/Loader.php
class CI_Loader {
/system/core/Controller.php
class CI_Controller {
/system/core/DB_driver.php
abstract class CI_DB_driver {
Greetings,
Ubel Jan
sneakyimp commentedon Jan 19, 2023
@ubeljan it's good to see what you've suggested here, but I'm not sure adding some collection of public properties to these classes is going to solve the problem in the general sense. I vaguely recall that CI3 assigns a LOT of dynamic properties to the controller. I can think of two other ways that we might fix this, but would like to hear from the CI devs and/or community.
Approach 1: __get and __set methods
Add the
$dynamic_propertiesvar and these methods to every class that has dynamic properties setApproach 2: AllowDynamicProperties attribute
Use the PHP AllowDynamicProperties attribute to tell PHP you'd like these classes to permit dynamic attributes:
To be clear, I have often lamented that CI uses undeclared properties so frequently -- IDEs don't know what kind of object you might be referring to, so all the code hinting features are disabled -- I just think one of these two approaches would be a more comprehensive and reasonable solution.
ubeljan commentedon Jan 20, 2023
For now I think the shortest way is approach 2.
To implement #[\AllowDynamicProperties] in the classes.
For now I have seen 5 places where to add #[\AllowDynamicProperties] to get a working website.
/system/core/URI.php
/system/core/Router.php
/system/core/Loader.php
/system/core/Controller.php
/system/core/DB_driver.php
sneakyimp commentedon Jan 20, 2023
This is helpful information! I wonder if perhaps @narfbg might sound off on our suggested solution here, and let us know what other classes have dynamic properties?
gxgpet commentedon Jan 27, 2023
The described problem in the first post of this issue is already fixed by #6173... It's just in the first PRs if you open the Pull Requests page.
Exactly what's happening on #6173.
That's why I waited for more incoming issues and pull requests on this matter. And thanks for your list of them. I compared with what we already in the previously mentioned PR and we covered all the cases.
Covered #6173.
Covered.
Covered.
Covered.
Covered.
Once again, please follow up on #6173... If you find other places, just point them out on that PR.