fix issue where running FileLocator::getClassname() on a directory would cause a PHP error - #8216
Conversation
|
How can we reproduce the error? It seems |
| { | ||
| if(is_dir($file)) { | ||
| return ''; | ||
| } |
There was a problem hiding this comment.
I think this code is okay (if the coding style is fixed), because a directory is never a class.
|
@kenjis you can reproduce the error by following the exception that is posted with a directory in your Commands folder. a dump of the array Produces: So there could be a bug with the get_filenames function you've referenced. This is running on PHP 7.4.21 |
|
Sorry, I had a modification made to the get_filenames so that it follows symlinks as well which wasn't updated with the additional include directories parameter. Its working now, still probably a worthwhile check to be making though. As a sidenote, should get_filenames just follow symlinks by default or as a global config option? |
|
$ ls -l
total 16
-rw-r--r-- 1 kenji staff 1579 10 27 16:48 BaseController.php
-rw-r--r-- 1 kenji staff 204 11 16 08:59 Home.php
lrwxr-xr-x 1 kenji staff 8 11 16 09:00 Symlink.php -> Home.php<?php
namespace App\Controllers;
class Home extends BaseController
{
public function index(): string
{
helper('filesystem');
dd(get_filenames(APPPATH . 'Controllers/'));
}
} |
It finds symlinks to files that are directly within the structure, but if a folder is symlinked it won't go into the folder due to the configuration of the RecursiveDirectoryIterator it would need to change from: to |

fix issue where running getClassName on a directory would cause a PHP
Description
This issue specifically comes up when you put commands in folders for better organization, the previous setup used
findQualifiedNameFromPathinstead ofgetClassname,getClassnamehas no checking to see if what is passed in is a directory, which could easily happen aslistFilescan return directories as well as files.Potential other solutions to this would be to prevent
listFilesfrom returning directories, or filtering the list of files prior to runninggetClassnameindiscoverCommandsChecklist: