Welcome Guest, Not a member yet? Register   Sign In
Factories problem following upgrade to V4.3.6
#1

(This post was last modified: 06-20-2023, 08:07 AM by Fido L Dido.)

Hi there,
I've today upgraded from V4.3.5 to V4.3.6. I've checked the upgrade notes and am not making use of any of the listed breaking changes. Despite this, my project has broken Sad
The problem appears to be in the loading of a factory.
I'm loading the factory as per documentation in my BaseController file:
Code:
$this->resultModel = Factories::models('ResultModel');

This is generating the following warnings in the logs:
Code:
WARNING - 2023-06-20 14:56:49 --> [DEPRECATED] trim(): Passing null to parameter #1 ($string) of type string is deprecated in SYSTEMPATH/Config/Factories.php on line 82.
1 SYSTEMPATH/Config/Factories.php(82): trim(null, '\\ ')
2 APPPATH/Models/NewsModel.php(32): CodeIgniter\Config\Factories::__callStatic('models', [...])
3 APPPATH/Controllers/BaseController.php(85): App\Models\NewsModel->__construct()
4 SYSTEMPATH/CodeIgniter.php(905): App\Controllers\BaseController->initController(Object(CodeIgniter\HTTP\IncomingRequest), Object(CodeIgniter\HTTP\Response), Object(CodeIgniter\Log\Logger))
5 SYSTEMPATH/CodeIgniter.php(488): CodeIgniter\CodeIgniter->createController()
6 SYSTEMPATH/CodeIgniter.php(366): CodeIgniter\CodeIgniter->handleRequest(null, Object(Config\Cache), false)
7 FCPATH/index.php(67): CodeIgniter\CodeIgniter->run()
WARNING - 2023-06-20 14:56:49 --> [DEPRECATED] trim(): Passing null to parameter #1 ($string) of type string is deprecated in SYSTEMPATH/Config/Factories.php on line 82.
1 SYSTEMPATH/Config/Factories.php(82): trim(null, '\\ ')
2 APPPATH/Models/UserModel.php(54): CodeIgniter\Config\Factories::__callStatic('models', [...])
3 APPPATH/Controllers/BaseController.php(94): App\Models\UserModel->__construct()
4 SYSTEMPATH/CodeIgniter.php(905): App\Controllers\BaseController->initController(Object(CodeIgniter\HTTP\IncomingRequest), Object(CodeIgniter\HTTP\Response), Object(CodeIgniter\Log\Logger))
5 SYSTEMPATH/CodeIgniter.php(488): CodeIgniter\CodeIgniter->createController()
6 SYSTEMPATH/CodeIgniter.php(366): CodeIgniter\CodeIgniter->handleRequest(null, Object(Config\Cache), false)
7 FCPATH/index.php(67): CodeIgniter\CodeIgniter->run()
WARNING - 2023-06-20 14:56:49 --> [DEPRECATED] trim(): Passing null to parameter #1 ($string) of type string is deprecated in SYSTEMPATH/Config/Factories.php on line 82.
1 SYSTEMPATH/Config/Factories.php(82): trim(null, '\\ ')
2 APPPATH/Models/UserModel.php(54): CodeIgniter\Config\Factories::__callStatic('models', [...])
3 [internal function]: App\Models\UserModel->__construct()
4 SYSTEMPATH/Database/MySQLi/Result.php(154): mysqli_result->fetch_object('App\\Models\\UserModel')
5 SYSTEMPATH/Database/BaseResult.php(159): CodeIgniter\Database\MySQLi\Result->fetchObject('App\\Models\\UserModel')
6 SYSTEMPATH/Database/BaseResult.php(114): CodeIgniter\Database\BaseResult->getCustomResultObject('App\\Models\\UserModel')
7 SYSTEMPATH/Database/BaseResult.php(391): CodeIgniter\Database\BaseResult->getResult('App\\Models\\UserModel')
8 SYSTEMPATH/Model.php(201): CodeIgniter\Database\BaseResult->getFirstRow('App\\Models\\UserModel')
9 SYSTEMPATH/BaseModel.php(557): CodeIgniter\Model->doFind(true, '25')
10 APPPATH/Controllers/BaseController.php(104): CodeIgniter\BaseModel->find('25')
11 SYSTEMPATH/CodeIgniter.php(905): App\Controllers\BaseController->initController(Object(CodeIgniter\HTTP\IncomingRequest), Object(CodeIgniter\HTTP\Response), Object(CodeIgniter\Log\Logger))
12 SYSTEMPATH/CodeIgniter.php(488): CodeIgniter\CodeIgniter->createController()
13 SYSTEMPATH/CodeIgniter.php(366): CodeIgniter\CodeIgniter->handleRequest(null, Object(Config\Cache), false)
14 FCPATH/index.php(67): CodeIgniter\CodeIgniter->run()
Other things have broken in my code, but they may well relate to problems loading this Factory, so I haven't investigated further yet. I'm no expert so haven't reported this as a bug because I'm not convinced that it's not me doing something wrong.

Just to add, I've downgraded back to V4.3.5 and the warnings have gone.
Reply
#2

(This post was last modified: 06-20-2023, 02:35 PM by kenjis.)

Cannot reproduce the error.

PHP Code:
<?php

namespace App\Controllers;

use 
CodeIgniter\Config\Factories;

class 
Home extends BaseController
{
    public function index()
    {
        Factories::models('ResultModel');
    }


I see a blank page, no error.
Reply
#3

Quote:trim(): Passing null to parameter #1 ($string) of type string is deprecated in SYSTEMPATH/Config/Factories.php on line 82.
1 SYSTEMPATH/Config/Factories.php(82): trim(null, '\\ ')

https://github.com/codeigniter4/CodeIgni...es.php#L82

As far as I know, there is no way to set the $arguments to null.
So I don't understand why the error occurs.
Reply
#4

Quote:7 SYSTEMPATH/Database/BaseResult.php(391): CodeIgniter\Database\BaseResult->getResult('App\\Models\\UserModel')
8 SYSTEMPATH/Model.php(201): CodeIgniter\Database\BaseResult->getFirstRow('App\\Models\\UserModel')

Why do you specify the class UserModel ? It is strange.
https://codeigniter4.github.io/CodeIgnit...tom-object
https://codeigniter4.github.io/CodeIgnit...lt-objects
Reply
#5

Thanks for taking the time to reply. I'll investigate further tomorrow as to what is going on and report back. I now suspect there is something peculiar about my code that I've overlooked.
Reply
#6

What PHP version are you running?
What did you Try? What did you Get? What did you Expect?

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

(06-20-2023, 11:05 PM)InsiteFX Wrote: What PHP version are you running?

I'm using PHP 8.2.7. I've noticed something problematic with my code. In the class I'm loading I think I may have chosen some poor method names which could inadvertently be overriding some of CodeIgniter's functionality leading to unpredicatable results. I'm going to investigate further and do some refactoring.
Reply
#8

(06-20-2023, 02:44 PM)kenjis Wrote:
Quote:7 SYSTEMPATH/Database/BaseResult.php(391): CodeIgniter\Database\BaseResult->getResult('App\\Models\\UserModel')
8 SYSTEMPATH/Model.php(201): CodeIgniter\Database\BaseResult->getFirstRow('App\\Models\\UserModel')

Why do you specify the class UserModel ? It is strange.
https://codeigniter4.github.io/CodeIgnit...tom-object
https://codeigniter4.github.io/CodeIgnit...lt-objects
This has really helped as I have now resolved the problem. I think there were two things wrong with my code creating unexpected results. The factory I was loading had methods that inadvertently conflicted with CI methods, so I have renamed them. Additionally my variable scopes were wrong when storing the result of loading the factory possibly giving rise to the null warnings in the logs. I've changed them to be private to each class and it has resolved the issue.

Thanks for pointing me in the right direction
Reply
#9

I have CodeIgniter 4 v4.3.6 running fine with php 8.2.7 on my live site.
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