CodeIgniter
CodeIgniter copied to clipboard
PHP 8.1.2 deprecation error, file_helper.php (line nr. 231)
Hey,
I seen this error on PHP 8.1.2 with a git clone of this repo (3.2.0-dev), sadly I can reproduce it ... I wanted to share it if someone can track it down and fix it.
A PHP Error was encountered
Severity: 8192
Message: Automatic conversion of false to array is deprecated
Filename: helpers/file_helper.php
Line Number: 231
The code involved :
$cached = $this->cache->file->cache_info();
https://github.com/bcit-ci/CodeIgniter/blob/develop/system/helpers/file_helper.php#L231
If I see the error again, ill try to find out what function exactly is being deprecated. (but sadly this was a once "off" issue)
I was able to reproduce the error; and turns out that a get_dir_file_info() on a index.html file returns a false.
I proposed a fix, but i'm not very familiar with the code, or what it should do, so probably might be rejected.
TEST:
$this->load->helper('file');
$models_info = get_dir_file_info(APPPATH.'models/');
var_dump($models_info);
Original with PHP 7.4 return error with:
Modif ....
elseif ($file[0] !== '.')
{
- $filedata = get_dir_file_info($source_dir.$file);
- $filedata['relative_path'] = $relative_path;
- $_filedata[] = $filedata;
+ $_filedata[$file] = get_file_info($source_dir.$file);
+ $_filedata[$file]['relative_path'] = $relative_path;
}
with modified code in PHP7.4 or PHP8.1:
Your modified code, return:
Thank you for the feedback, since you found a better/correct solution, please make a PR so mine can be rejected. I only wanted to share the error, and quickly find a way to suppress it.