php / php/php-src

Feature: walker function: walker(".") returns an object model of the entire directory / an expansive alternative for scandir()

Open
#22,104 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Feature Status: Needs Triage
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

Here is my current code for demonstrating the purpose. The dev community shall decide on the final verdict.

<?php
    function walker($directory) {
        foreach (scandir($directory) as $item) {
            if ($item == '.' || $item == '..') continue;
            if ($directory == "." && ($item == "api.php" || $item == 'index.html')) continue;
            $dl[$item] = [
                "item_type" => is_dir("{$directory}/{$item}") ? "folder" : "file",
                "child" => walker("{$directory}/{$item}"),
            ];
        }
        return $dl;
    }
?>

Here's how I'm currently using it :) with some html css and js
Image

How it looks like when I use echo and json_encode.
Image

I'll be making a pull request if it got a lot of good impressions.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the proposed walker($directory) example and its intended object model for recursive directory traversal. Compare the request with the existing scandir() behavior and determine whether a concrete PHP API, scope, and completion criteria can be defined; the issue currently names no source files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.