I want be to be able to re-write the code of an existing PHP function in an abstract manner.
Here is an example:
scandir() scans a directory for files and folders, and returns the relative paths '.' and '..' .
While I could just create a new function to run scandir() and remove these entries, I want to try and re-write the code for scandir() to allow for an extra parameter, then add a flag to not include these paths.
So instead of this:
$files = [];
foreach(scandir($path) as $index => $ref) {
if(!in_array(['.','..'], $ref)) {
$files[] = $ref;
}
}
I can do this:
$files = scandir($path, true);
Is this possible without rewriting the entirety of scandir() with override_function() ?
scandir_alastor
function, taking the two parameters which will internally call the defaultscandir
.