rfc:glob_streamwrapper_support

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:glob_streamwrapper_support [2022/08/15 19:31] timintrfc:glob_streamwrapper_support [2022/10/24 13:50] (current) timint
Line 1: Line 1:
 ====== PHP RFC: StreamWrapper Support for glob() ====== ====== PHP RFC: StreamWrapper Support for glob() ======
 +
   * Version: 1.0   * Version: 1.0
   * Date: 2022-08-15   * Date: 2022-08-15
   * Author: Timmy Almroth, timmy.almroth@gmail.com   * Author: Timmy Almroth, timmy.almroth@gmail.com
-  * Status: Draft+  * Status: Under Discussion
   * First Published at: https://wiki.php.net/rfc/glob_streamwrapper_support   * First Published at: https://wiki.php.net/rfc/glob_streamwrapper_support
 +
 +**Status: Aborted**
 +
 +**Comment: This RFC has been aborted as no convenient solution or workaround was found for Alpine platform. / Timmy**
  
 ===== Introduction ===== ===== Introduction =====
-The current implementation of glob() is a thin wrapper for POSIX glob(3). Apart from PHP's other [[https://www.php.net/manual/en/ref.filesystem.php|Filesystem Functions]] it is missing support for StreamWrappers.+''glob()'' is a function in PHP to list and filter files and/or folders using a globbing pattern. The current implementation of ''glob()'' is a thin wrapper for POSIX glob(3). While all the [[https://www.php.net/manual/en/ref.filesystem.php|Filesystem Functions]] in PHP supports StreamWrappers, ''glob()'' does not.
  
 Workarounds can be a struggle. Some projects may rely on regular expressions which are different from globbing. Some may attempt the use of fnmatch() which does not support all the features of glob() like brace expansions. Workarounds can be a struggle. Some projects may rely on regular expressions which are different from globbing. Some may attempt the use of fnmatch() which does not support all the features of glob() like brace expansions.
Line 15: Line 20:
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
-No backwards incompatibility+Fully backwards compatibile
  
 ===== Proposed PHP Version(s) ===== ===== Proposed PHP Version(s) =====
Line 21: Line 26:
  
 ===== RFC Impact ===== ===== RFC Impact =====
-No noted impacts as glob() will continue working as beforeapart from the new StreamWrapper support. Performance tests so far have shown no anomalies.+The glob opendir implementation would be replaced with a wrapper supporting streams. It is possible to produce a fallback condition leaving local file system operations as is. But testing so far have not shown any performance anomalies or incompatibilities. So the intention is to also use the new wrapper for local filesystem operations. 
 + 
 +open_basedir check will be removed from result filtering in favour of the already new implemented one in wrapper's opendir. 
 + 
 +If a StreamWrapper supports listing contents, it will supported by glob(). There will be edge cases where a streamwrapper is not intended to or does not support listing contents of a resource, e.g. http:, data:, compress.zlib:. These cases are not unique to glob() as the same problemematics applies to scandir(). glob() returns an empty array for invalid paths today and will continue doing so for wrappers that can't be used to return a list of contents. 
 + 
 +Which streamwrapper that can be used with glob() is not a limitation of glob()but the streamwrapper itself. PHP's current ftp streamwrapper might not support listing files in a directory, but a 3rd party wrapper for ftp might. 
 + 
 +A word of advice can be put in the documentation that clearifies how glob() will not work with these edge case wrappers. But again, this applies to the current implementation of scandir() also.
  
 ===== Unaffected PHP Functionality ===== ===== Unaffected PHP Functionality =====
-Local file system operations i.e. glob('*.ext') would not be affected by this addition.+''glob()'',  GlobalIterator and %%glob:\\%% for local filesystem will return the same results. 
 + 
 +Wrappers not intended to return a list of contents will continue returning an empty array as glob does today. 
 + 
 +Edit (Oct 2): As noted by @bukka; the use of GLOB_ALTDIRFUNC is a non-standard implementation that doesn't seem to be supported on Alpine. Meaning streamwrappers for glob() would remain unsupported on Alpine systems unless solved.
  
 ===== Future Scope ===== ===== Future Scope =====
Line 33: Line 50:
  
 ===== Patches and Tests ===== ===== Patches and Tests =====
-Patches and tests are being produced in the Github Feature Request [[https://github.com/php/php-src/issues/9224|#9224]]. +A PoC has been produced in the Github Feature Request thread [[https://github.com/php/php-src/issues/9224|#9224]]. 
-Final patch will be produced by Github user @KapitanOczywisty.+Final patch will be produced by Github user @KapitanOczywisty if this RFC is approved.
  
 ===== Implementation ===== ===== Implementation =====
rfc/glob_streamwrapper_support.1660591909.txt.gz · Last modified: 2022/08/15 19:31 by timint