glob_variation-win32.phpt 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. --TEST--
  2. Test glob() function: usage variations
  3. --SKIPIF--
  4. <?php
  5. if (substr(PHP_OS, 0, 3) != 'WIN') {
  6. die('skip.. only for Windows');
  7. }
  8. ?>
  9. --FILE--
  10. <?php
  11. echo "*** Testing glob() : usage variations ***\n";
  12. $file_path = __DIR__;
  13. // temp dir created
  14. mkdir("$file_path/glob_variation");
  15. mkdir("$file_path/glob_variation/wonder");
  16. // temp files created
  17. $fp = fopen("$file_path/glob_variation/wonder12345", "w");
  18. fclose($fp);
  19. $fp = fopen("$file_path/glob_variation/wonder;123456", "w");
  20. fclose($fp);
  21. $patterns = array (
  22. "$file_path/glob_variation/*der*",
  23. "$file_path/glob_variation/?onder*",
  24. "$file_path/glob_variation/w*der?*",
  25. "$file_path/glob_variation/*der5",
  26. "$file_path/glob_variation/??onder*",
  27. "$file_path/glob_variation/***der***",
  28. "$file_path/glob_variation/++onder*",
  29. "$file_path/glob_variation/WONDER5\0",
  30. '$file_path/glob_variation/wonder5',
  31. "$file_path/glob_variation/?wonder?",
  32. "$file_path/glob_variation/wonder?",
  33. TRUE // boolean true
  34. );
  35. $counter = 1;
  36. /* loop through $patterns to match each $pattern with the files created
  37. using glob() */
  38. foreach($patterns as $pattern) {
  39. echo "\n-- Iteration $counter --\n";
  40. try {
  41. var_dump( glob($pattern) ); // default arguments
  42. var_dump( glob($pattern, GLOB_MARK) );
  43. var_dump( glob($pattern, GLOB_NOSORT) );
  44. var_dump( glob($pattern, GLOB_NOCHECK) );
  45. var_dump( glob($pattern, GLOB_NOESCAPE) );
  46. var_dump( glob($pattern, GLOB_ERR) );
  47. } catch (Error $e) {
  48. echo $e->getMessage(), "\n";
  49. }
  50. $counter++;
  51. }
  52. echo "\n*** Testing glob() with pattern within braces ***\n";
  53. var_dump( glob("$file_path/glob_variation/*{5}", GLOB_BRACE) );
  54. // delete temp files and dir
  55. unlink("$file_path/glob_variation/wonder12345");
  56. unlink("$file_path/glob_variation/wonder;123456");
  57. rmdir("$file_path/glob_variation/wonder");
  58. rmdir("$file_path/glob_variation");
  59. echo "\n*** Testing glob() on directories ***\n";
  60. // temp dir created to check for pattern matching the sub dir created in it
  61. mkdir("$file_path/glob_variation/wonder1/wonder2", 0777, true);
  62. $counter = 1;
  63. /* loop through $patterns to match each $pattern with the directories created
  64. using glob() */
  65. foreach($patterns as $pattern) {
  66. echo "-- Iteration $counter --\n";
  67. try {
  68. var_dump( glob($pattern, GLOB_ONLYDIR) );
  69. } catch (Error $e) {
  70. echo $e->getMessage(), "\n";
  71. }
  72. $counter++;
  73. }
  74. echo "Done\n";
  75. ?>
  76. --CLEAN--
  77. <?php
  78. $file_path = __DIR__;
  79. rmdir("$file_path/glob_variation/wonder1/wonder2");
  80. rmdir("$file_path/glob_variation/wonder1/");
  81. rmdir("$file_path/glob_variation/");
  82. ?>
  83. --EXPECTF--
  84. *** Testing glob() : usage variations ***
  85. -- Iteration 1 --
  86. array(3) {
  87. [0]=>
  88. string(%d) "%s/glob_variation/wonder"
  89. [1]=>
  90. string(%d) "%s/glob_variation/wonder12345"
  91. [2]=>
  92. string(%d) "%s/glob_variation/wonder;123456"
  93. }
  94. array(3) {
  95. [0]=>
  96. string(%d) "%s/glob_variation/wonder12345"
  97. [1]=>
  98. string(%d) "%s/glob_variation/wonder;123456"
  99. [2]=>
  100. string(%d) "%s/glob_variation/wonder\"
  101. }
  102. array(3) {
  103. [0]=>
  104. string(%d) "%s/glob_variation/wonder"
  105. [1]=>
  106. string(%d) "%s/glob_variation/wonder12345"
  107. [2]=>
  108. string(%d) "%s/glob_variation/wonder;123456"
  109. }
  110. array(3) {
  111. [0]=>
  112. string(%d) "%s/glob_variation/wonder"
  113. [1]=>
  114. string(%d) "%s/glob_variation/wonder12345"
  115. [2]=>
  116. string(%d) "%s/glob_variation/wonder;123456"
  117. }
  118. array(3) {
  119. [0]=>
  120. string(%d) "%s/glob_variation/wonder"
  121. [1]=>
  122. string(%d) "%s/glob_variation/wonder12345"
  123. [2]=>
  124. string(%d) "%s/glob_variation/wonder;123456"
  125. }
  126. array(3) {
  127. [0]=>
  128. string(%d) "%s/glob_variation/wonder"
  129. [1]=>
  130. string(%d) "%s/glob_variation/wonder12345"
  131. [2]=>
  132. string(%d) "%s/glob_variation/wonder;123456"
  133. }
  134. -- Iteration 2 --
  135. array(3) {
  136. [0]=>
  137. string(%d) "%s/glob_variation/wonder"
  138. [1]=>
  139. string(%d) "%s/glob_variation/wonder12345"
  140. [2]=>
  141. string(%d) "%s/glob_variation/wonder;123456"
  142. }
  143. array(3) {
  144. [0]=>
  145. string(%d) "%s/glob_variation/wonder12345"
  146. [1]=>
  147. string(%d) "%s/glob_variation/wonder;123456"
  148. [2]=>
  149. string(%d) "%s/glob_variation/wonder\"
  150. }
  151. array(3) {
  152. [0]=>
  153. string(%d) "%s/glob_variation/wonder"
  154. [1]=>
  155. string(%d) "%s/glob_variation/wonder12345"
  156. [2]=>
  157. string(%d) "%s/glob_variation/wonder;123456"
  158. }
  159. array(3) {
  160. [0]=>
  161. string(%d) "%s/glob_variation/wonder"
  162. [1]=>
  163. string(%d) "%s/glob_variation/wonder12345"
  164. [2]=>
  165. string(%d) "%s/glob_variation/wonder;123456"
  166. }
  167. array(3) {
  168. [0]=>
  169. string(%d) "%s/glob_variation/wonder"
  170. [1]=>
  171. string(%d) "%s/glob_variation/wonder12345"
  172. [2]=>
  173. string(%d) "%s/glob_variation/wonder;123456"
  174. }
  175. array(3) {
  176. [0]=>
  177. string(%d) "%s/glob_variation/wonder"
  178. [1]=>
  179. string(%d) "%s/glob_variation/wonder12345"
  180. [2]=>
  181. string(%d) "%s/glob_variation/wonder;123456"
  182. }
  183. -- Iteration 3 --
  184. array(2) {
  185. [0]=>
  186. string(%d) "%s/glob_variation/wonder12345"
  187. [1]=>
  188. string(%d) "%s/glob_variation/wonder;123456"
  189. }
  190. array(2) {
  191. [0]=>
  192. string(%d) "%s/glob_variation/wonder12345"
  193. [1]=>
  194. string(%d) "%s/glob_variation/wonder;123456"
  195. }
  196. array(2) {
  197. [0]=>
  198. string(%d) "%s/glob_variation/wonder12345"
  199. [1]=>
  200. string(%d) "%s/glob_variation/wonder;123456"
  201. }
  202. array(2) {
  203. [0]=>
  204. string(%d) "%s/glob_variation/wonder12345"
  205. [1]=>
  206. string(%d) "%s/glob_variation/wonder;123456"
  207. }
  208. array(2) {
  209. [0]=>
  210. string(%d) "%s/glob_variation/wonder12345"
  211. [1]=>
  212. string(%d) "%s/glob_variation/wonder;123456"
  213. }
  214. array(2) {
  215. [0]=>
  216. string(%d) "%s/glob_variation/wonder12345"
  217. [1]=>
  218. string(%d) "%s/glob_variation/wonder;123456"
  219. }
  220. -- Iteration 4 --
  221. array(0) {
  222. }
  223. array(0) {
  224. }
  225. array(0) {
  226. }
  227. array(1) {
  228. [0]=>
  229. string(%d) "%s/glob_variation/*der5"
  230. }
  231. array(0) {
  232. }
  233. array(0) {
  234. }
  235. -- Iteration 5 --
  236. array(0) {
  237. }
  238. array(0) {
  239. }
  240. array(0) {
  241. }
  242. array(1) {
  243. [0]=>
  244. string(%d) "%s/glob_variation/??onder*"
  245. }
  246. array(0) {
  247. }
  248. array(0) {
  249. }
  250. -- Iteration 6 --
  251. array(3) {
  252. [0]=>
  253. string(%d) "%s/glob_variation/wonder"
  254. [1]=>
  255. string(%d) "%s/glob_variation/wonder12345"
  256. [2]=>
  257. string(%d) "%s/glob_variation/wonder;123456"
  258. }
  259. array(3) {
  260. [0]=>
  261. string(%d) "%s/glob_variation/wonder12345"
  262. [1]=>
  263. string(%d) "%s/glob_variation/wonder;123456"
  264. [2]=>
  265. string(%d) "%s/glob_variation/wonder\"
  266. }
  267. array(3) {
  268. [0]=>
  269. string(%d) "%s/glob_variation/wonder"
  270. [1]=>
  271. string(%d) "%s/glob_variation/wonder12345"
  272. [2]=>
  273. string(%d) "%s/glob_variation/wonder;123456"
  274. }
  275. array(3) {
  276. [0]=>
  277. string(%d) "%s/glob_variation/wonder"
  278. [1]=>
  279. string(%d) "%s/glob_variation/wonder12345"
  280. [2]=>
  281. string(%d) "%s/glob_variation/wonder;123456"
  282. }
  283. array(3) {
  284. [0]=>
  285. string(%d) "%s/glob_variation/wonder"
  286. [1]=>
  287. string(%d) "%s/glob_variation/wonder12345"
  288. [2]=>
  289. string(%d) "%s/glob_variation/wonder;123456"
  290. }
  291. array(3) {
  292. [0]=>
  293. string(%d) "%s/glob_variation/wonder"
  294. [1]=>
  295. string(%d) "%s/glob_variation/wonder12345"
  296. [2]=>
  297. string(%d) "%s/glob_variation/wonder;123456"
  298. }
  299. -- Iteration 7 --
  300. array(0) {
  301. }
  302. array(0) {
  303. }
  304. array(0) {
  305. }
  306. array(1) {
  307. [0]=>
  308. string(%d) "%s/glob_variation/++onder*"
  309. }
  310. array(0) {
  311. }
  312. array(0) {
  313. }
  314. -- Iteration 8 --
  315. glob(): Argument #1 ($pattern) must not contain any null bytes
  316. -- Iteration 9 --
  317. array(0) {
  318. }
  319. array(0) {
  320. }
  321. array(0) {
  322. }
  323. array(1) {
  324. [0]=>
  325. string(%d) "$file_path/glob_variation/wonder5"
  326. }
  327. array(0) {
  328. }
  329. array(0) {
  330. }
  331. -- Iteration 10 --
  332. array(0) {
  333. }
  334. array(0) {
  335. }
  336. array(0) {
  337. }
  338. array(1) {
  339. [0]=>
  340. string(%d) "%s/glob_variation/?wonder?"
  341. }
  342. array(0) {
  343. }
  344. array(0) {
  345. }
  346. -- Iteration 11 --
  347. array(0) {
  348. }
  349. array(0) {
  350. }
  351. array(0) {
  352. }
  353. array(1) {
  354. [0]=>
  355. string(%d) "%s/glob_variation/wonder?"
  356. }
  357. array(0) {
  358. }
  359. array(0) {
  360. }
  361. -- Iteration 12 --
  362. array(0) {
  363. }
  364. array(0) {
  365. }
  366. array(0) {
  367. }
  368. array(1) {
  369. [0]=>
  370. string(%d) "1"
  371. }
  372. array(0) {
  373. }
  374. array(0) {
  375. }
  376. *** Testing glob() with pattern within braces ***
  377. array(1) {
  378. [0]=>
  379. string(%d) "%s/glob_variation/wonder12345"
  380. }
  381. *** Testing glob() on directories ***
  382. -- Iteration 1 --
  383. array(1) {
  384. [0]=>
  385. string(%d) "%s/glob_variation/wonder1"
  386. }
  387. -- Iteration 2 --
  388. array(1) {
  389. [0]=>
  390. string(%d) "%s/glob_variation/wonder1"
  391. }
  392. -- Iteration 3 --
  393. array(1) {
  394. [0]=>
  395. string(%d) "%s/glob_variation/wonder1"
  396. }
  397. -- Iteration 4 --
  398. array(0) {
  399. }
  400. -- Iteration 5 --
  401. array(0) {
  402. }
  403. -- Iteration 6 --
  404. array(1) {
  405. [0]=>
  406. string(%d) "%s/glob_variation/wonder1"
  407. }
  408. -- Iteration 7 --
  409. array(0) {
  410. }
  411. -- Iteration 8 --
  412. glob(): Argument #1 ($pattern) must not contain any null bytes
  413. -- Iteration 9 --
  414. array(0) {
  415. }
  416. -- Iteration 10 --
  417. array(0) {
  418. }
  419. -- Iteration 11 --
  420. array(1) {
  421. [0]=>
  422. string(%d) "%s/glob_variation/wonder1"
  423. }
  424. -- Iteration 12 --
  425. array(0) {
  426. }
  427. Done