Skip to content

Bug: Cache FileHandler error: Automatic conversion of false to array is deprecated  #7338

Closed
@markkortleverwebavance

Description

@markkortleverwebavance

PHP Version

8.2

CodeIgniter4 Version

4.3.2

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Linux

Which server did you use?

apache

Database

mysql 5.6

What happened?

An error occurs when you got a sub folder inside the cache dir.
It happens in the cache -> FileHandler

ErrorException
Automatic conversion of false to array is deprecated

if $_filedata[$file] = $this->getFileInfo($sourceDir . $file); returns false since $file is not a file but a sub dir then you will get the error above. $_filedata[$file] then is bool(false) instead of an array

StackTrace:
SYSTEMPATH/Cache/Handlers/FileHandler.php : 351   —  CodeIgniter\Debug\Exceptions->errorHandler ( [arguments](http://localhost:3000/api/dictionaries/translations/1#) )

344 
345             // Used to be foreach (scandir($source_dir, 1) as $file), but scandir() is simply not as fast
346             while (false !== ($file = readdir($fp))) {
347                 if (is_dir($sourceDir . $file) && $file[0] !== '.' && $topLevelOnly === false) {
348                     $this->getDirFileInfo($sourceDir . $file . DIRECTORY_SEPARATOR, $topLevelOnly, true);
349                 } elseif ($file[0] !== '.') {
350                     $_filedata[$file]                  = $this->getFileInfo($sourceDir . $file);
351                     $_filedata[$file]['relative_path'] = $relativePath;
352                 }
353             }
354 
355             closedir($fp);
356 
357             return $_filedata;
358         }
SYSTEMPATH/Cache/Handlers/FileHandler.php : 199   —  CodeIgniter\Cache\Handlers\FileHandler->getDirFileInfo ( [arguments](http://localhost:3000/api/dictionaries/translations/1#) )

192     }
193 
194     /**
195      * {@inheritDoc}
196      */
197     public function getCacheInfo()
198     {
199         return $this->getDirFileInfo($this->path);
200     }
201 
202     /**
203      * {@inheritDoc}
204      */
205     public function getMetaData(string $key)
206     {

Steps to Reproduce

create a subdir inside the cache dir and then the $this->cache->getCacheInfo(); function

Expected Output

No error

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix themwaiting for infoIssues or pull requests that need further clarification from the author

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions