Creation of dynamic property CI_URI::$config is deprecated
Asked Answered
C

3

32

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: C:\xampp\htdocs\inv_perpus\index.php Line: 288 Function: require_once

Curb answered 15/1, 2023 at 4:19 Comment(7)
You're polluting an object by trying to set a property against it that does not existCrenelation
Looks like you need to update your CodeIgniter (to version 3.1 maybe). What version do you currently have?Crenelation
my codeigniter is version 3, because it's my school assignment & my xampp version is 8.2.0Curb
I raised an issue for you, and opened a pull request to fix it: github.com/bcit-ci/CodeIgniter/issues/6192Crenelation
Tell your school to stop forcing you to use packages built for versions of PHP that are end of life and no longer receiving security updates. CI3 was built for and remains compatible with PHP5.4, that means it’s missing a whole world of improvements and featuresCrenelation
You can't normally use old versions of third-party libraries in latest PHP versions. You should either upgrade to latest CodeIgniter 4 release or downgrade to an old enough PHP version.Starwort
See also: #74879389Astonish
B
49

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/database/DB_driver.php

#[\AllowDynamicProperties]

abstract class CI_DB_driver {

Source: https://github.com/bcit-ci/CodeIgniter/pull/6193#issuecomment-1397221543

Baculiform answered 13/4, 2023 at 21:20 Comment(2)
these changes gave me an ERR_CONTENT_DECODING_FAILED 200 error, which I resolved by setting in php.ini zlib.output_compression=On see: https://mcmap.net/q/470899/-ajax-returning-err_content_decoding_failed-200-using-codeigniterXanthippe
This answer was a leap in the right direction. In my case, I had a few additional changes that became necessary but those were indicated in the error outputs. Now it all works great! So do not give up if you see more errors just by following this answer. Keep going.Determinative
C
16

This is an issue with CodeIgniter.

in /system/core/URI.php you can add this to the top of the class to fix it:

/**
 * CI Config
 *
 * @var CI_Config
 */
public $config;

Or, you can disable deprecation warnings in one of two ways:

php.ini

error_reporting = E_ALL & ~E_DEPRECATED

in code:

ini_set('error_reporting', E_ALL & ~E_DEPRECATED);

of course it is bad practice to disable these errors, as these errors should be heard loudly and fixed quickly.

I opened an issue with CodeIgniter and opened a pull-request to resolve this for you in their next release. They should be onto it relatively quickly and release a patch soon thereafter so just let the course of it play out and silence the error for now

This issue is resolved in CodeIgniter 4 however

Crenelation answered 15/1, 2023 at 4:41 Comment(0)
A
-2

Also not a best practice, but instead of set the error reporting, in my case it was better solution to simply added an @ charachter to the beginning of each reported lines.

Alien answered 15/2, 2023 at 9:54 Comment(1)
For deprecated features, this is a pretty bad idea, as you should replace them before updating to the next PHP version. Ignoring the deprecation message means that your code will stop working without any informationClemen

© 2022 - 2024 — McMap. All rights reserved.