005_variation2.phpt 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. --TEST--
  2. Test fileatime(), filemtime(), filectime() & touch() functions : usage variation
  3. --CREDITS--
  4. Dave Kelsey <d_kelsey@uk.ibm.com>
  5. --SKIPIF--
  6. <?php
  7. if (substr(PHP_OS, 0, 3) == 'WIN') {
  8. die('skip.. only for Non Windows Systems');
  9. }
  10. ?>
  11. --FILE--
  12. <?php
  13. /*
  14. Prototype: int fileatime ( string $filename );
  15. Description: Returns the time the file was last accessed, or FALSE
  16. in case of an error. The time is returned as a Unix timestamp.
  17. Prototype: int filemtime ( string $filename );
  18. Description: Returns the time the file was last modified, or FALSE
  19. in case of an error.
  20. Prototype: int filectime ( string $filename );
  21. Description: Returns the time the file was last changed, or FALSE
  22. in case of an error. The time is returned as a Unix timestamp.
  23. Prototype: bool touch ( string $filename [, int $time [, int $atime]] );
  24. Description: Attempts to set the access and modification times of the file
  25. named in the filename parameter to the value given in time.
  26. */
  27. /*
  28. Prototype: void stat_fn(string $filename);
  29. Description: Prints access, modification and change times of a file
  30. */
  31. function stat_fn( $filename ) {
  32. echo "\n-- File '$filename' --\n";
  33. echo "-- File access time is => ";
  34. echo fileatime($filename)."\n";
  35. clearstatcache();
  36. echo "-- File modification time is => ";
  37. echo filemtime($filename)."\n";
  38. clearstatcache();
  39. echo "-- inode change time is => ";
  40. echo filectime($filename)."\n";
  41. clearstatcache();
  42. }
  43. echo "*** Testing fileattime(), filemtime(), filectime() & touch() : usage variations ***\n";
  44. echo "\n*** testing touch ***\n";
  45. $a = touch(NULL);
  46. $b = touch(false);
  47. $c = touch('');
  48. $d = touch(' ');
  49. $e = touch('|');
  50. var_dump($a);
  51. var_dump($b);
  52. var_dump($c);
  53. var_dump($d);
  54. var_dump($e);
  55. echo "\n*** testing file info ***";
  56. stat_fn(NULL);
  57. stat_fn(false);
  58. stat_fn('');
  59. stat_fn(' ');
  60. stat_fn('|');
  61. var_dump(unlink(' '));
  62. var_dump(unlink('|'));
  63. echo "Done";
  64. ?>
  65. --EXPECTF--
  66. *** Testing fileattime(), filemtime(), filectime() & touch() : usage variations ***
  67. *** testing touch ***
  68. bool(false)
  69. bool(false)
  70. bool(false)
  71. bool(true)
  72. bool(true)
  73. *** testing file info ***
  74. -- File '' --
  75. -- File access time is =>
  76. -- File modification time is =>
  77. -- inode change time is =>
  78. -- File '' --
  79. -- File access time is =>
  80. -- File modification time is =>
  81. -- inode change time is =>
  82. -- File '' --
  83. -- File access time is =>
  84. -- File modification time is =>
  85. -- inode change time is =>
  86. -- File ' ' --
  87. -- File access time is => %d
  88. -- File modification time is => %d
  89. -- inode change time is => %d
  90. -- File '|' --
  91. -- File access time is => %d
  92. -- File modification time is => %d
  93. -- inode change time is => %d
  94. bool(true)
  95. bool(true)
  96. Done