sobatcoding.com - Cara mengatasi error creation of dynamic property CI_URI::$config is deprecated
Pernah mengalami masalah muncul pesan error seperti ini saat instalasi Codeigniter 3? Pesan error yang muncul kurang lebih seperti berikut
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_URI::$config is deprecated
Severity: 8192
Message: Creation of dynamic property CI_Router::$uri is deprecated
Severity: 8192
Message: Creation of dynamic property Welcome::$benchmark is deprecated
Message: Creation of dynamic property Welcome::$hooks is deprecated
Message: Creation of dynamic property Welcome::$config is deprecated
Message: Creation of dynamic property Welcome::$log is deprecated
Message: Creation of dynamic property Welcome::$utf8 is deprecated
Message: Creation of dynamic property Welcome::$uri is deprecated
Message: Creation of dynamic property Welcome::$router is deprecated
Message: Creation of dynamic property Welcome::$exceptions is deprecated
Message: Creation of dynamic property Welcome::$output is deprecated
Message: Creation of dynamic property Welcome::$security is deprecated
Message: Creation of dynamic property Welcome::$input is deprecated
Message: Creation of dynamic property Welcome::$lang is deprecated
Message: Creation of dynamic property Welcome::$load is deprecated
Message: Creation of dynamic property Welcome::$db is deprecated
Message: Creation of dynamic property CI_DB_mysqli_driver::$failover is deprecated
Message: Creation of dynamic property CI_Loader::$benchmark is deprecated
Message: Creation of dynamic property CI_Loader::$hooks is deprecated
Masalah ini pernah dialami saat install Codeigniter 3 dengan XAMPP atau install Codeigniter 3 dengan Laragon dengan PHP versi 8.2
Merujuk dari referensi artikel berikut https://forum.codeigniter.com/printthread.php?tid=82678 ada dua cara untuk mengatasi problem di atas:
Tambahkan variable public di beberapa file yang muncul indikasi error seperti system/core/URI.php
File ./system/core/URI.php tambahkan variable public $config; di dalam Class URI
/**
* Permitted URI chars
*
* PCRE character group allowed in URI segments
*
* @var string
*/
protected $_permitted_uri_chars;
/**
* CI Config
*
* @var CI_Config
*/
public $config;
/**
* Class constructor
*
* @return void
*/
public function __construct()
{
$this->config =& load_class('Config', 'core');
di file ./system/core/Router.php
class CI_Router {
...
public $uri;
...
di file ./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;
di file ./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;
Cara yang kedua adalah dengan cara implementasi atau menambahkan #[\AllowDynamicProperties] di setiap file yang muncul indikasi error sebelum definisi Class
* @package CodeIgniter
* @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
* @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/)
* @license https://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 1.0.0
* @filesource
*/
defined('BASEPATH') OR exit('No direct script access allowed');
#[\AllowDynamicProperties]
/**
* URI Class
*
* Parses URIs and determines routing
*
* @package CodeIgniter
* @subpackage Libraries
* @category URI
* @author EllisLab Dev Team
* @link https://codeigniter.com/user_guide/libraries/uri.html
*/
class CI_URI {
Kalian tambahkan masing-masing di file URI.php, Router.php, Loader.php dan DB_Driver.php sebelum definisi Class
/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 {
Semoga artikel di atas bermanfaat dan selamat mencoba
Komentar 1