WP_Filesystem_ftpsockets::dirlist( string $path = '.', bool $include_hidden = true, bool $recursive = false ): array|false
- Since
- 2.5.0
- Source
wp-admin/includes/class-wp-filesystem-ftpsockets.php:650
Compatibility
- WordPress
- since 2.5.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$pathstringoptional- Path to directory or file.Default:
'.' $recursivebooloptional- Whether to recursively include file details in nested directories.
Default false.Default:false
Return value
array|false- Array of arrays containing file information. False if unable to list directory contents.
...$0arrayArray of file information. Note that some elements may not be available on all filesystems.$namestringName of the file or directory.$permsstring*nix representation of permissions.$permsnstringOctal representation of permissions.$numberint|string|falseFile number. May be a numeric string. False if not available.$ownerstring|falseOwner name or ID, or false if not available.$groupstring|falseFile permissions group, or false if not available.$sizeint|string|falseSize of file in bytes. May be a numeric string. False if not available.$lastmodunixint|string|falseLast modified unix timestamp. May be a numeric string. False if not available.$lastmodstring|falseLast modified month (3 letters) and day (without leading 0), or false if not available.$timestring|falseLast modified time, or false if not available.$typestringType of resource. 'f' for file, 'd' for directory, 'l' for link.$filesarray|falseIf a directory and$recursiveis true, contains another array of files. False if unable to list directory contents.
Performance profile
How much work a call to WP_Filesystem_ftpsockets::dirlist() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Light
- Scaling
- Scales with input
- Instructions
- 24–39
- Plugin surface
- None
- Called by
- 5
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 92.
Nothing here hands control to plugin code.
5 places in core call this, so the cost is paid more often than your own code shows.
What one call costs · 6 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Filesystem_ftpsockets::dirlist() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!->is_file() && empty($list) && !->exists() | 24 | ->is_file(), mbstring_binary_safe_encoding(), ->dirlist(), ->exists(), reset_mbstring_encoding() |
!->is_file() && !empty($list) | 27–28 | ->is_file(), mbstring_binary_safe_encoding(), ->dirlist(), trailingslashit(), reset_mbstring_encoding() |
!->is_file() && empty($list) && ->exists() | 31–32 | ->is_file(), mbstring_binary_safe_encoding(), ->dirlist(), ->exists(), trailingslashit(), reset_mbstring_encoding() |
->is_file() && empty($list) && !->exists() | 31 | ->is_file(), basename(), mbstring_binary_safe_encoding(), ->dirlist(), ->exists(), reset_mbstring_encoding() |
->is_file() && !empty($list) | 34–35 | ->is_file(), basename(), mbstring_binary_safe_encoding(), ->dirlist(), trailingslashit(), reset_mbstring_encoding() |
->is_file() && empty($list) && ->exists() | 38–39 | ->is_file(), basename(), mbstring_binary_safe_encoding(), ->dirlist(), ->exists(), trailingslashit(), reset_mbstring_encoding() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 92 | 24–39 | 14 | |
| 8.5 | 92 | 24–39 | 14 | |
| 8.4 | 92 | 24–39 | 14 | 5 fewer instructions than PHP 8.3 |
| 8.3 | 97 | 24–41 | 14 | |
| 8.2 | 97 | 24–41 | 14 | |
| 8.1 | 97 | 24–41 | 14 | |
| 7.4 | 97 | 24–41 | 14 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 7
- mbstring_binary_safe_encoding()Sets the mbstring internal encoding to a binary safe encoding when func_overload is enabled.
- reset_mbstring_encoding()Resets the mbstring internal encoding to a users previously set encoding.
- trailingslashit()Appends a trailing slash.
- WP_Filesystem_ftpsockets::is_file()Checks if resource is a file.
- WP_Filesystem_ftpsockets::exists()Checks if a file or directory exists.
- WP_Filesystem_ftpsockets::dirlist()Gets details for files in a directory or a specific file.
- WP_Filesystem_ftpsockets::getnumchmodfromh()
Used by · 5
- WP_Filesystem_ftpsockets::chmod()Changes filesystem permissions.
- WP_Filesystem_ftpsockets::dirlist()Gets details for files in a directory or a specific file.
- WP_Filesystem_ftpsockets::getchmod()Gets the permissions of the specified file or filepath in their octal format.
- WP_Filesystem_ftpsockets::group()Gets the file's group.
- WP_Filesystem_ftpsockets::owner()Gets the file owner.
Source code
public function dirlist( $path = '.', $include_hidden = true, $recursive = false ) { if ( $this->is_file( $path ) ) { $limit_file = basename( $path ); $path = dirname( $path ) . '/'; } else { $limit_file = false; } mbstring_binary_safe_encoding(); $list = $this->ftp->dirlist( $path ); if ( empty( $list ) && ! $this->exists( $path ) ) { reset_mbstring_encoding(); return false; } $path = trailingslashit( $path ); $ret = array(); foreach ( $list as $struc ) { if ( '.' === $struc['name'] || '..' === $struc['name'] ) { continue; } if ( ! $include_hidden && '.' === $struc['name'][0] ) { continue; } if ( $limit_file && $struc['name'] !== $limit_file ) { continue; } if ( 'd' === $struc['type'] ) { if ( $recursive ) { $struc['files'] = $this->dirlist( $path . $struc['name'], $include_hidden, $recursive ); } else { $struc['files'] = array(); } } // Replace symlinks formatted as "source -> target" with just the source name. if ( $struc['islink'] ) { $struc['name'] = preg_replace( '/(\s*->\s*.*)$/', '', $struc['name'] ); } // Add the octal representation of the file permissions. $struc['permsn'] = $this->getnumchmodfromh( $struc['perms'] ); $ret[ $struc['name'] ] = $struc; } reset_mbstring_encoding(); return $ret; }Changelog
Introduced in 2.5.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 tag, from
src/wp-admin/includes/class-wp-filesystem-ftpsockets.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.