简体   繁体   English

Glob 模式不匹配任何内容

[英]Glob pattern does not match anything

NOTE: The pattern in question has been removed from the PHP documentation since this thread was created.注意:自从创建此线程以来,相关模式已从 PHP 文档中删除。

According to the PHP documentation , the pattern ... matches all subdirectories recursively, but when I try using it, no files are matched.根据PHP 文档,模式...递归匹配所有子目录,但是当我尝试使用它时,没有文件匹配。

According to the documentation, glob hasn't changed since PHP 5.1, but if it matters, I am using PHP 7.2.24.根据文档,自 PHP 5.1 以来, glob没有改变,但如果重要的话,我使用的是 PHP 7.2.24。

Directory structure:目录结构:

.
├── bar
│   └── bar_file
└── foo
    ├── 1
    │   └── foo_1_file
    └── foo_file

PHP: PHP:

var_dump(glob('./.../*')); // prints array(0) {}
var_dump(glob('./.../foo_file')); // prints array(0) {}

I know there is a workaround for this problem, but I would like to know if there is a PHP native solution or if there isn't, why the PHP reference documentation is defective.我知道有解决此问题的方法,但我想知道是否有 PHP 本机解决方案,或者如果没有,为什么 PHP 参考文档有缺陷。

The documentation is incomplete or even incorrect.文档不完整甚至不正确。 As of Nov 2019, there is no code to explicitly support recursive glob syntax in PHP and the underlying operating system libraries are unlikely to support it either.截至 2019 年 11 月,PHP 中没有明确支持递归 glob 语法的代码,底层操作系统库也不太可能支持它。

  1. There is no recursive glob syntax in IEEE 1003.1 IEEE 1003.1中没有递归 glob 语法

  2. PHP UNIX implementation delegates to GLOB(3) from a standard C library. PHP UNIX 实现从标准 C 库委托给GLOB(3) On Linux this will most likely be glibc which has no support for recursive syntax .在 Linux 上,这很可能是不支持递归语法的 glibc。

  3. PHP Windows implementation has no support for directory recursion PHP Windows 实现不支持目录递归

  4. None of the glob tests in PHP test suite include a test that covers a triple dot (...) syntax. PHP 测试套件中的所有 glob 测试都不包含涵盖三点 (...) 语法的测试。

  5. According to the commit message of the change that introduced glob pattern syntax to PHP documentation, the list of special characters was based on the ones supported by djgpp libc library.根据在 PHP 文档中引入 glob 模式语法的更改的提交消息,特殊字符列表基于 djgpp libc 库支持的字符列表。 The djgpp manpage states that the triple dot syntax is a nod to an old VMS feature. djgpp联机帮助页指出,三点语法是对旧 VMS 功能的致敬。

    ... Matches all the subdirectories, recursively (VMS aficionados, rejoice.). ... 递归匹配所有子目录(VMS 爱好者,欢欣鼓舞。)。

All of this is strong evidence that the recursive syntax listed in the documentation will not work unless PHP is running on a platform that has support for it, eg DJGPP on DOS or old Windows.所有这些都有力地证明了文档中列出的递归语法将不起作用,除非 PHP 在支持它的平台上运行,例如 DOS 上的 DJGPP 或旧的 Windows。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM