球形模式不匹配任何内容 [英] Glob pattern does not match anything

查看:88
本文介绍了球形模式不匹配任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:自创建此线程以来,相关模式已从PHP文档中删除。



根据 PHP文档,格式为 ... 递归地匹配所有子目录,但是当我尝试使用它时,没有文件匹配。



根据文档 glob 自PHP 5.1起没有更改,但是如果有关系,我使用的是PHP 7.2.24。



目录结构:

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

PHP:

  var_dump(glob('./.../*')); //打印array(0){} 
var_dump(glob(’./.../ foo_file’)); //打印array(0){}

我知道有一个此问题的解决方法,但是我想知道是否有PHP本机解决方案,否则,为什么PHP参考文档有缺陷。

解决方案

文档不完整,甚至不正确。截至2019年11月,没有代码可在PHP中显式支持递归glob语法,并且底层操作系统库也不可能支持它。


  1. IEEE 1003.1 中没有递归glob语法p>


  2. PHP UNIX实现委托给 GLOB(3)来自标准C库。在Linux上,最有可能是glibc,它不支持递归语法



  3. PHP Windows实现不支持目录递归



  4. PHP测试套件中的所有glob测试 a>包括覆盖三点(...)语法的测试。



  5. 根据更改,将glob模式语法引入了PHP文档,特殊字符列表基于那些由djgpp libc库支持。 djgpp 联机帮助页指出,三点语法是对


    ......以递归方式匹配所有子目录(VMS爱好者,很高兴!)。




所有这些有力的证据表明,除非PHP在具有以下功能的平台上运行,否则文档中列出的递归语法将不起作用支持它,例如在DOS或旧Windows上使用DJGPP。


NOTE: The pattern in question has been removed from the PHP documentation since this thread was created.

According to the PHP documentation, the pattern ... matches all subdirectories recursively, but when I try using it, no files are matched.

According to the documentation, glob hasn't changed since PHP 5.1, but if it matters, I am using PHP 7.2.24 .

Directory structure:

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

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.

解决方案

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.

  1. There is no recursive glob syntax in IEEE 1003.1

  2. PHP UNIX implementation delegates to GLOB(3) from a standard C library. On Linux this will most likely be glibc which has no support for recursive syntax.

  3. PHP Windows implementation has no support for directory recursion

  4. None of the glob tests in PHP test suite include a test that covers a triple dot (...) syntax.

  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. The djgpp manpage states that the triple dot syntax is a nod to an old VMS feature.

    ... Matches all the subdirectories, recursively (VMS aficionados, rejoice!).

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, e.g. DJGPP on DOS or old Windows.

这篇关于球形模式不匹配任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆