fseek_variation1.phpt 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. --TEST--
  2. Test fseek() function : usage variations - different types for offset
  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. // Initialise function arguments not being substituted (if any)
  15. $fp = fopen(__FILE__, 'r');
  16. $whence = SEEK_SET;
  17. //get an unset variable
  18. $unset_var = 10;
  19. unset ($unset_var);
  20. class testClass {
  21. public function __toString() {
  22. return "testClass";
  23. }
  24. }
  25. //array of values to iterate over
  26. $values = array(
  27. // float data
  28. 10.5,
  29. -10.5,
  30. 10.7654321E-10,
  31. .5,
  32. // array data
  33. array(),
  34. array(0),
  35. array(1),
  36. array(1, 2),
  37. array('color' => 'red', 'item' => 'pen'),
  38. // null data
  39. NULL,
  40. null,
  41. // boolean data
  42. true,
  43. false,
  44. TRUE,
  45. FALSE,
  46. // empty data
  47. "",
  48. '',
  49. // string data
  50. "string",
  51. 'string',
  52. // object data
  53. new testClass(),
  54. // undefined data
  55. $undefined_var,
  56. // unset data
  57. $unset_var,
  58. );
  59. // loop through each element of the array for offset
  60. foreach($values as $value) {
  61. echo @"\nArg value $value \n";
  62. var_dump( fseek($fp, $value, $whence) );
  63. var_dump( ftell($fp));
  64. };
  65. fclose($fp);
  66. echo "Done";
  67. ?>
  68. --EXPECTF--
  69. *** Testing fseek() : usage variations ***
  70. Arg value 10.5
  71. int(0)
  72. int(10)
  73. Arg value -10.5
  74. int(-1)
  75. int(10)
  76. Arg value 1.07654321E-9
  77. int(0)
  78. int(0)
  79. Arg value 0.5
  80. int(0)
  81. int(0)
  82. Arg value Array
  83. Warning: fseek() expects parameter 2 to be long, array given in %s on line %d
  84. bool(false)
  85. int(0)
  86. Arg value Array
  87. Warning: fseek() expects parameter 2 to be long, array given in %s on line %d
  88. bool(false)
  89. int(0)
  90. Arg value Array
  91. Warning: fseek() expects parameter 2 to be long, array given in %s on line %d
  92. bool(false)
  93. int(0)
  94. Arg value Array
  95. Warning: fseek() expects parameter 2 to be long, array given in %s on line %d
  96. bool(false)
  97. int(0)
  98. Arg value Array
  99. Warning: fseek() expects parameter 2 to be long, array given in %s on line %d
  100. bool(false)
  101. int(0)
  102. Arg value
  103. int(0)
  104. int(0)
  105. Arg value
  106. int(0)
  107. int(0)
  108. Arg value 1
  109. int(0)
  110. int(1)
  111. Arg value
  112. int(0)
  113. int(0)
  114. Arg value 1
  115. int(0)
  116. int(1)
  117. Arg value
  118. int(0)
  119. int(0)
  120. Arg value
  121. Warning: fseek() expects parameter 2 to be long, string given in %s on line %d
  122. bool(false)
  123. int(0)
  124. Arg value
  125. Warning: fseek() expects parameter 2 to be long, string given in %s on line %d
  126. bool(false)
  127. int(0)
  128. Arg value string
  129. Warning: fseek() expects parameter 2 to be long, string given in %s on line %d
  130. bool(false)
  131. int(0)
  132. Arg value string
  133. Warning: fseek() expects parameter 2 to be long, string given in %s on line %d
  134. bool(false)
  135. int(0)
  136. Arg value testClass
  137. Warning: fseek() expects parameter 2 to be long, object given in %s on line %d
  138. bool(false)
  139. int(0)
  140. Arg value
  141. int(0)
  142. int(0)
  143. Arg value
  144. int(0)
  145. int(0)
  146. Done