fileobject_003.phpt 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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(dirname(__FILE__) . '/' . 'fileobject_001a.txt', 't', substr(dirname(__FILE__),-1));
  40. test(dirname(__FILE__) . '/', substr(dirname(__FILE__),-1), 'l');
  41. test(dirname(__FILE__), substr(dirname(__FILE__),-1), 'l');
  42. ?>
  43. ===DONE===
  44. <?php exit(0); ?>
  45. --EXPECTF--
  46. ===0===
  47. object(SplFileInfo)#%d (2) {
  48. ["pathName":"SplFileInfo":private]=>
  49. string(%d) "%s"
  50. ["fileName":"SplFileInfo":private]=>
  51. string(%d) "fileobject_001a.txt"
  52. }
  53. object(SplFileInfo)#%d (2) {
  54. ["pathName":"SplFileInfo":private]=>
  55. string(%d) "%s"
  56. ["fileName":"SplFileInfo":private]=>
  57. string(%d) "fileobject_001a.txt"
  58. }
  59. bool(false)
  60. bool(true)
  61. bool(true)
  62. %s(%d) "%sfileobject_001a.txt"
  63. string(%d) "%sfileobject_001a.txt"
  64. bool(true)
  65. string(19) "fileobject_001a.txt"
  66. bool(true)
  67. string(%d) "%stests"
  68. bool(true)
  69. string(%d) "%sfileobject_001a.txt"
  70. string(19) "fileobject_001a.txt"
  71. string(%d) "%stests"
  72. ===1===
  73. object(SplFileInfo)#%d (2) {
  74. ["pathName":"SplFileInfo":private]=>
  75. string(%d) "%s"
  76. ["fileName":"SplFileInfo":private]=>
  77. string(%d) "%s"
  78. }
  79. object(SplFileInfo)#%d (2) {
  80. ["pathName":"SplFileInfo":private]=>
  81. string(%d) "%s"
  82. ["fileName":"SplFileInfo":private]=>
  83. string(%d) "%s"
  84. }
  85. bool(false)
  86. bool(true)
  87. bool(true)
  88. LogicException: Cannot use SplFileObject with directories
  89. LogicException: Cannot use SplFileObject with directories
  90. ===2===
  91. object(SplFileInfo)#%d (2) {
  92. ["pathName":"SplFileInfo":private]=>
  93. string(%d) "%s"
  94. ["fileName":"SplFileInfo":private]=>
  95. string(%d) "%s"
  96. }
  97. object(SplFileInfo)#%d (2) {
  98. ["pathName":"SplFileInfo":private]=>
  99. string(%d) "%s"
  100. ["fileName":"SplFileInfo":private]=>
  101. string(%d) "%s"
  102. }
  103. bool(false)
  104. bool(true)
  105. bool(true)
  106. LogicException: Cannot use SplFileObject with directories
  107. LogicException: Cannot use SplFileObject with directories
  108. ===DONE===