Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8.1.2 deprecation error, file_helper.php (line nr. 231) #6122

Open
svennd opened this issue Mar 27, 2022 · 3 comments · May be fixed by #6125
Open

PHP 8.1.2 deprecation error, file_helper.php (line nr. 231) #6122

svennd opened this issue Mar 27, 2022 · 3 comments · May be fixed by #6125

Comments

@svennd
Copy link
Contributor

svennd commented Mar 27, 2022

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)

svennd added a commit to svennd/CodeIgniter that referenced this issue Mar 27, 2022
propose fix for bcit-ci#6122 unsure if this is a valid fix, my code (while using this function) doesn't actually use this function.

$filedata will return bool(false) on
 "/var/www/html/project/application/cache/index.html"

Causing the error posted in the issue.
@svennd
Copy link
Contributor Author

svennd commented Mar 27, 2022

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.

@totoprayogo1916
Copy link
Contributor

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:
image

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:
image

Your modified code, return:
image

@svennd
Copy link
Contributor Author

svennd commented Apr 2, 2022

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.

@totoprayogo1916 totoprayogo1916 linked a pull request Apr 6, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
@totoprayogo1916 @svennd and others