fseek_variation2.phpt 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. --TEST--
  2. Test fseek() function : usage variations - different types for whence
  3. --CREDITS--
  4. Dave Kelsey <d_kelsey@uk.ibm.com>
  5. --FILE--
  6. <?php
  7. /* Prototype : proto int fseek(resource fp, int offset [, int whence])
  8. * Description: Seek on a file pointer
  9. * Source code: ext/standard/file.c
  10. * Alias to functions: gzseek
  11. */
  12. echo "*** Testing fseek() : usage variations ***\n";
  13. error_reporting(E_ALL & ~E_NOTICE);
  14. $fp = fopen(__FILE__, 'r');
  15. $offset = 3;
  16. //get an unset variable
  17. $unset_var = 10;
  18. unset ($unset_var);
  19. //array of values to iterate over
  20. $values = array(
  21. // outside of whence range
  22. -100,
  23. 100,
  24. // float data
  25. 10.5,
  26. -10.5,
  27. 10.1234567e10,
  28. 10.7654321E-10,
  29. .5,
  30. // null data
  31. NULL,
  32. null,
  33. // boolean data
  34. true,
  35. false,
  36. TRUE,
  37. FALSE,
  38. // empty data
  39. "",
  40. '',
  41. // string data
  42. "string",
  43. 'string',
  44. // undefined data
  45. $undefined_var,
  46. // unset data
  47. $unset_var,
  48. );
  49. // loop through each element of the array for whence
  50. foreach($values as $value) {
  51. echo "\nArg value $value \n";
  52. var_dump( fseek($fp, $offset, $value) );
  53. var_dump( ftell($fp));
  54. };
  55. fclose($fp);
  56. echo "Done";
  57. ?>
  58. --EXPECTF--
  59. *** Testing fseek() : usage variations ***
  60. Arg value -100
  61. int(-1)
  62. int(0)
  63. Arg value 100
  64. int(-1)
  65. int(0)
  66. Arg value 10.5
  67. int(-1)
  68. int(0)
  69. Arg value -10.5
  70. int(-1)
  71. int(0)
  72. Arg value 101234567000
  73. int(-1)
  74. int(0)
  75. Arg value 1.07654321E-9
  76. int(0)
  77. int(3)
  78. Arg value 0.5
  79. int(0)
  80. int(3)
  81. Arg value
  82. int(0)
  83. int(3)
  84. Arg value
  85. int(0)
  86. int(3)
  87. Arg value 1
  88. int(0)
  89. int(6)
  90. Arg value
  91. int(0)
  92. int(3)
  93. Arg value 1
  94. int(0)
  95. int(6)
  96. Arg value
  97. int(0)
  98. int(3)
  99. Arg value
  100. Warning: fseek() expects parameter 3 to be long, string given in %s on line %d
  101. bool(false)
  102. int(3)
  103. Arg value
  104. Warning: fseek() expects parameter 3 to be long, string given in %s on line %d
  105. bool(false)
  106. int(3)
  107. Arg value string
  108. Warning: fseek() expects parameter 3 to be long, string given in %s on line %d
  109. bool(false)
  110. int(3)
  111. Arg value string
  112. Warning: fseek() expects parameter 3 to be long, string given in %s on line %d
  113. bool(false)
  114. int(3)
  115. Arg value
  116. int(0)
  117. int(3)
  118. Arg value
  119. int(0)
  120. int(3)
  121. Done