fileobject_003.phpt 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. --TEST--
  2. SPL: SplFileInfo cloning
  3. --FILE--
  4. <?php
  5. function test($name, $lc, $lp)
  6. {
  7. static $i = 0;
  8. echo "===$i===\n";
  9. $i++;
  10. $o = new SplFileInfo($name);
  11. var_dump($o);
  12. $c = clone $o;
  13. var_dump($c);
  14. var_dump($o === $c);
  15. var_dump($o == $c);
  16. var_dump($o->getPathname() == $c->getPathname());
  17. try {
  18. $f = new SplFileObject($name);
  19. var_dump($name);
  20. var_dump($f->getPathName());
  21. $l = substr($f->getPathName(), -1);
  22. var_dump($l != '/' && $l != '\\' && $l == $lc);
  23. var_dump($f->getFileName());
  24. $l = substr($f->getFileName(), -1);
  25. var_dump($l != '/' && $l != '\\' && $l == $lc);
  26. var_dump($f->getPath());
  27. $l = substr($f->getPath(), -1);
  28. var_dump($l != '/' && $l != '\\' && $l == $lp);
  29. } catch (LogicException $e) {
  30. echo "LogicException: ".$e->getMessage()."\n";
  31. }
  32. try {
  33. $fo = $o->openFile();
  34. var_dump($fo->getPathName(), $fo->getFileName(), $fo->getPath());
  35. } catch (LogicException $e) {
  36. echo "LogicException: ".$e->getMessage()."\n";
  37. }
  38. }
  39. test(__DIR__ . '/' . 'fileobject_001a.txt', 't', substr(__DIR__,-1));
  40. test(__DIR__ . '/', substr(__DIR__,-1), 'l');
  41. test(__DIR__, substr(__DIR__,-1), 'l');
  42. ?>
  43. --EXPECTF--
  44. ===0===
  45. object(SplFileInfo)#%d (2) {
  46. ["pathName":"SplFileInfo":private]=>
  47. string(%d) "%s"
  48. ["fileName":"SplFileInfo":private]=>
  49. string(%d) "fileobject_001a.txt"
  50. }
  51. object(SplFileInfo)#%d (2) {
  52. ["pathName":"SplFileInfo":private]=>
  53. string(%d) "%s"
  54. ["fileName":"SplFileInfo":private]=>
  55. string(%d) "fileobject_001a.txt"
  56. }
  57. bool(false)
  58. bool(true)
  59. bool(true)
  60. %s(%d) "%sfileobject_001a.txt"
  61. string(%d) "%sfileobject_001a.txt"
  62. bool(true)
  63. string(19) "fileobject_001a.txt"
  64. bool(true)
  65. string(%d) "%stests"
  66. bool(true)
  67. string(%d) "%sfileobject_001a.txt"
  68. string(19) "fileobject_001a.txt"
  69. string(%d) "%stests"
  70. ===1===
  71. object(SplFileInfo)#%d (2) {
  72. ["pathName":"SplFileInfo":private]=>
  73. string(%d) "%s"
  74. ["fileName":"SplFileInfo":private]=>
  75. string(%d) "%s"
  76. }
  77. object(SplFileInfo)#%d (2) {
  78. ["pathName":"SplFileInfo":private]=>
  79. string(%d) "%s"
  80. ["fileName":"SplFileInfo":private]=>
  81. string(%d) "%s"
  82. }
  83. bool(false)
  84. bool(true)
  85. bool(true)
  86. LogicException: Cannot use SplFileObject with directories
  87. LogicException: Cannot use SplFileObject with directories
  88. ===2===
  89. object(SplFileInfo)#%d (2) {
  90. ["pathName":"SplFileInfo":private]=>
  91. string(%d) "%s"
  92. ["fileName":"SplFileInfo":private]=>
  93. string(%d) "%s"
  94. }
  95. object(SplFileInfo)#%d (2) {
  96. ["pathName":"SplFileInfo":private]=>
  97. string(%d) "%s"
  98. ["fileName":"SplFileInfo":private]=>
  99. string(%d) "%s"
  100. }
  101. bool(false)
  102. bool(true)
  103. bool(true)
  104. LogicException: Cannot use SplFileObject with directories
  105. LogicException: Cannot use SplFileObject with directories