Closed itisjoby closed 1 year ago
If I understand correctly, you yourself is setting the session property in $this->session
. In such case, it is not the framework's bug.
hi actually it was an example, if i set $this->foo in the view page i get same error. is there any way to use $this->variable name with out triggering the php 8.2 deprecation warning other than modifing view class inside ci4 system folder.
Sorry, we do not support dynamic property. Because it is deprecated in PHP 8.2.
Why do you need to use dynamic property? It is bad practice.
Why do you need to add the properties dynamically? It seems you do not need them. Instead of $this->session
use a variable instead $session
,
PHP Version
8.2
CodeIgniter4 Version
4.3.1
CodeIgniter4 Installation Method
Composer (using
codeigniter4/appstarter
)Which operating systems have you tested for this bug?
Linux
Which server did you use?
apache
Database
mongodb
What happened?
php 8.2 doesnot support dynamic property. we are able to add #[\AllowDynamicProperties] to prevent deprecation warnings in controller, model and libraries. but in view we couldnot do anything. below is the sample log in ci4 error log file.
WARNING - 2023-03-02 10:37:29 --> [DEPRECATED] Creation of dynamic property CodeIgniter\View\View::$session is deprecated in APPPATH/Views/admin/members/linked_members.php on line 4. 1 SYSTEMPATH/View/View.php(213): include('APPPATH/Views/admin/members/linked_members.php') 2 SYSTEMPATH/View/View.php(216): CodeIgniter\View\View->CodeIgniter\View{closure}() 3 SYSTEMPATH/Common.php(1184): CodeIgniter\View\View->render('admin/members/linked_members', [], true) 4 APPPATH/Libraries/Layout.php(1415): view('admin/members/linked_members', [...]) 5 APPPATH/Libraries/Layout.php(1486): App\Libraries\Layout->process_view('admin/members/linked_members', [...], [...]) 6 APPPATH/Controllers/Admin/Members.php(3528): App\Libraries\Layout->return_view('admin/members/linked_members', [...], [...]) 7 SYSTEMPATH/CodeIgniter.php(934): App\Controllers\Admin\Members->linkedProfiles() 8 SYSTEMPATH/CodeIgniter.php(499): CodeIgniter\CodeIgniter->runController(Object(App\Controllers\Admin\Members)) 9 SYSTEMPATH/CodeIgniter.php(368): CodeIgniter\CodeIgniter->handleRequest(null, Object(Config\Cache), false) 10 FCPATH/index.php(67): CodeIgniter\CodeIgniter->run()
Steps to Reproduce
declare a global variable in view file.
$this->session = \Config\Services::session();
we use $this->session->get() format because we are converting from ci3 to ci4 and felt easy to do this way
Expected Output
no deprecation warnings in log file.
Anything else?
No response