1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- --TEST--
- Test feof() function : basic functionality
- --CREDITS--
- Dave Kelsey <d_kelsey@uk.ibm.com>
- --FILE--
- <?php
- echo "*** Testing feof() : basic functionality ***\n";
- $tmpFile1 = __FILE__.".tmp1";
- $h = fopen($tmpFile1, 'wb');
- $count = 10;
- for ($i = 1; $i <= $count; $i++) {
- fwrite($h, "some data $i\n");
- }
- fclose($h);
- echo "\n*** testing reading complete file using feof to stop ***\n";
- $h = fopen($tmpFile1, 'rb');
- //feof is not set to true until you try to read past the end of file.
- //so fgets will be called even if we are at the end of the file on
- //last time to set the eof flag but it will fail to read.
- $lastline = "";
- while (!feof($h)) {
- $previousLine = $lastline;
- $lastline = fgets($h);
- }
- echo $previousLine;
- var_dump($lastline); // this should be false
- fclose($h);
- $tmpFile2 = __FILE__.".tmp2";
- $h = fopen($tmpFile2, 'wb+');
- $count = 10;
- echo "*** writing $count lines, testing feof ***\n";
- for ($i = 1; $i <=$count; $i++) {
- fwrite($h, "some data $i\n");
- var_dump(feof($h));
- }
- echo "*** testing feof on unclosed file after a read ***\n";
- fread($h, 100);
- var_dump(feof($h));
- $eofPointer = ftell($h);
- echo "*** testing feof after a seek to near the beginning ***\n";
- fseek($h, 20, SEEK_SET);
- var_dump(feof($h));
- echo "*** testing feof after a seek to end ***\n";
- fseek($h, $eofPointer, SEEK_SET);
- var_dump(feof($h));
- echo "*** testing feof after a seek passed the end ***\n";
- fseek($h, $eofPointer + 1000, SEEK_SET);
- var_dump(feof($h));
- echo "*** closing file, testing eof ***\n";
- fclose($h);
- try {
- feof($h);
- } catch (TypeError $e) {
- echo $e->getMessage(), "\n";
- }
- unlink($tmpFile1);
- unlink($tmpFile2);
- echo "Done";
- ?>
- --EXPECT--
- *** Testing feof() : basic functionality ***
- *** testing reading complete file using feof to stop ***
- some data 10
- bool(false)
- *** writing 10 lines, testing feof ***
- bool(false)
- bool(false)
- bool(false)
- bool(false)
- bool(false)
- bool(false)
- bool(false)
- bool(false)
- bool(false)
- bool(false)
- *** testing feof on unclosed file after a read ***
- bool(true)
- *** testing feof after a seek to near the beginning ***
- bool(false)
- *** testing feof after a seek to end ***
- bool(false)
- *** testing feof after a seek passed the end ***
- bool(false)
- *** closing file, testing eof ***
- feof(): supplied resource is not a valid stream resource
- Done
|