Welcome Guest, Not a member yet? Register   Sign In
Creation of dynamic property DEPRECATED
#1

To create a multilanguages web site I've added into the initController method in BaseController file the following code that causes a warning in log :
Severity Message
info Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
warning [DEPRECATED] Creation of dynamic property App\Controllers\Home::$session is deprecated in APPPATH\Controllers\BaseController.php on line 68

What's wrong and how to fix it? Thanks

Code:
    if (session_status() == PHP_SESSION_NONE) {
        $this->session = \Config\Services::session();
    } 
Reply
#2

Add this line to your BaseController.php:

PHP Code:
protected $session
You also might want to read this:
https://php.watch/versions/8.2/dynamic-p...deprecated
Reply
#3

This works for me in the BaseController.

PHP Code:
use Config\Services;

/**
 * E.g.: $this->session = \Config\Services::session();
 * Ensure that the session is started and running
 */
if (session_status() == PHP_SESSION_NONE) {
    $this->session Services::session();

What did you Try? What did you Get? What did you Expect?

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

Thanks a lot for feedback guys...still lots to learn about CI4....
Reply
#5

(12-26-2024, 12:09 AM)InsiteFX Wrote: This works for me in the BaseController.

PHP Code:
use Config\Services;

/**
 * E.g.: $this->session = \Config\Services::session();
 * Ensure that the session is started and running
 */
if (session_status() == PHP_SESSION_NONE) {
    $this->session Services::session();


But you still explicitly declare $session as a property?
Reply
#6

Yes, but I don't use it, I just make sure it's loaded.
I use the session help like so:

PHP Code:
session()->set($data);

$name session()->get('name');

// etc; 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB