--TEST--
Test fopen(), fclose() & feof() functions: basic functionality
--FILE--
<?php
/* 
 Prototype: resource fopen(string $filename, string $mode 
                            [, bool $use_include_path [, resource $context]] );
 Description: Opens file or URL.

 Prototype: bool fclose ( resource $handle );
 Description: Closes an open file pointer

 Prototype: bool feof ( resource $handle );
 Description: Tests for end-of-file on a file pointer
*/

echo "*** Testing basic operations of fopen() and fclose() functions ***\n";
$modes = array(
  
"w",
  
"wb",
  
"wt",
  
"w+",
  
"w+b",
  
"w+t",

  
"r",
  
"rb",
  
"rt",
  
"r+",
  
"r+b",
  
"r+t",

  
"a",
  
"ab",
  
"at",
  
"a+",
  
"a+t",
  
"a+b"
);

for( 
$i=0$i<count($modes); $i++ ) {
  echo 
"\n-- Iteration with mode '$modes[$i]' --\n";

  
$filename dirname(__FILE__)."/007_basic.tmp";
  
// check fopen()
  
$handle fopen($filename$modes[$i]);
  
var_dump($handle );
  
var_dumpftell($handle) );
  
var_dumpfeof($handle) );

  
// check fclose()
  
var_dumpfclose($handle) );
  
var_dump$handle );
  
// confirm the closure, using ftell() and feof(), expect, false
  
var_dumpftell($handle) );
  
var_dumpfeof($handle) );
}

// remove the temp file
unlink($filename);

$x_modes = array(
  
"x",
  
"xb",
  
"xt",
  
"x+",
  
"x+b",
  
"x+t"
);

for( 
$i=0$i<count($x_modes); $i++ ) {
  echo 
"\n-- Iteration with mode '$x_modes[$i]' --\n";
  
$handle fopen($filename$x_modes[$i]);
  
var_dump($handle );
  
var_dumpftell($handle) );
  
var_dumpfeof($handle) );

  
// check fclose()
  
var_dumpfclose($handle) );
  
var_dump$handle );
  
// confirm the closure, using ftell() and feof(), expect, false
  
var_dumpftell($handle) );
  
var_dumpfeof($handle) );
  
var_dump$handle );

  
// remove the file
  
unlink$filename );
}

echo 
"\n*** Done ***\n";
--
EXPECTF--
*** 
Testing basic operations of fopen() and fclose() functions ***

-- 
Iteration with mode 'w' --
resource(%dof type (stream)
int(0)
bool(false)
bool(true)
resource(%dof type (Unknown)

Warningftell(): %d is not a valid stream resource in %s on line %d
bool
(false)

Warningfeof(): %d is not a valid stream resource in %s on line %d
bool
(false)

-- 
Iteration with mode 'wb' --
resource(%dof type (stream)
int(0)
bool(false)
bool(true)
resource(%dof type (Unknown)

Warningftell(): %d is not a valid stream resource in %s on line %d
bool
(false)

Warningfeof(): %d is not a valid stream resource in %s on line %d
bool
(false)

-- 
Iteration with mode 'wt' --
resource(%dof type (stream)
int(0)
bool(false)
bool(true)
resource(%dof type (Unknown)

Warningftell(): %d is not a valid stream resource in %s on line %d
bool
(false)

Warningfeof(): %d is not a valid stream resource in %s on line %d
bool
(false)

-- 
Iteration with mode 'w+' --
resource(%dof type (stream)
int(0)
bool(false)
bool(true)
resource(%dof type (Unknown)

Warningftell(): %d is not a valid stream resource in %s on line %d
bool
(false)

Warningfeof(): %d is not a valid stream resource in %s on line %d
bool
(false)

-- 
Iteration with mode 'w+b' --
resource(%dof type (stream)
int(0)
bool(false)
bool(true)
resource(%dof type (Unknown)

Warningftell(): %d is not a valid stream resource in %s on line %d
bool
(false)

Warningfeof(): %d is not a valid stream resource in %s on line %d
bool
(false)

-- 
Iteration with mode 'w+t' --
resource(%dof type (stream)
int(0)
bool(false)
bool(true)
resource(%dof type (Unknown)

Warningftell(): %d is not a valid stream resource in %s on line %d
bool
(false)

Warningfeof(): %d is not a valid stream resource in %s on line %d
bool
(false)

-- 
Iteration with mode 'r' --
resource(%dof type (stream)
int(0)
bool(false)
bool(true)
resource(%dof type (Unknown)

Warningftell(): %d is not a valid stream resource in %s on line %d
bool
(false)

Warningfeof(): %d is not a valid stream resource in %s on line %d
bool
(false)

-- 
Iteration with mode 'rb' --
resource(%dof type (stream)
int(0)
bool(false)
bool(true)
resource(%dof type (Unknown)

Warningftell(): %d is not a valid stream resource in %s on line %d
bool
(false)

Warningfeof(): %d is not a valid stream resource in %s on line %d
bool
(false)

-- 
Iteration with mode 'rt' --
resource(%dof type (stream)
int(0)
bool(false)
bool(true)
resource(%dof type (Unknown)

Warningftell(): %d is not a valid stream resource in %s on line %d
bool
(false)

Warningfeof(): %d is not a valid stream resource in %s on line %d
bool
(false)

-- 
Iteration with mode 'r+' --
resource(%dof type (stream)
int(0)
bool(false)
bool(true)
resource(%dof type (Unknown)

Warningftell(): %d is not a valid stream resource in %s on line %d
bool
(false)

Warningfeof(): %d is not a valid stream resource in %s on line %d
bool
(false)

-- 
Iteration with mode 'r+b' --
resource(%dof type (stream)
int(0)
bool(false)
bool(true)
resource(%dof type (Unknown)

Warningftell(): %d is not a valid stream resource in %s on line %d
bool
(false)

Warningfeof(): %d is not a valid stream resource in %s on line %d
bool
(false)

-- 
Iteration with mode 'r+t' --
resource(%dof type (stream)
int(0)
bool(false)
bool(true)
resource(%dof type (Unknown)

Warningftell(): %d is not a valid stream resource in %s on line %d
bool
(false)

Warningfeof(): %d is not a valid stream resource in %s on line %d
bool
(false)

-- 
Iteration with mode 'a' --
resource(%dof type (stream)
int(0)
bool(false)
bool(true)
resource(%dof type (Unknown)

Warningftell(): %d is not a valid stream resource in %s on line %d
bool
(false)

Warningfeof(): %d is not a valid stream resource in %s on line %d
bool
(false)

-- 
Iteration with mode 'ab' --
resource(%dof type (stream)
int(0)
bool(false)
bool(true)
resource(%dof type (Unknown)

Warningftell(): %d is not a valid stream resource in %s on line %d
bool
(false)

Warningfeof(): %d is not a valid stream resource in %s on line %d
bool
(false)

-- 
Iteration with mode 'at' --
resource(%dof type (stream)
int(0)
bool(false)
bool(true)
resource(%dof type (Unknown)

Warningftell(): %d is not a valid stream resource in %s on line %d
bool
(false)

Warningfeof(): %d is not a valid stream resource in %s on line %d
bool
(false)

-- 
Iteration with mode 'a+' --
resource(%dof type (stream)
int(0)
bool(false)
bool(true)
resource(%dof type (Unknown)

Warningftell(): %d is not a valid stream resource in %s on line %d
bool
(false)

Warningfeof(): %d is not a valid stream resource in %s on line %d
bool
(false)

-- 
Iteration with mode 'a+t' --
resource(%dof type (stream)
int(0)
bool(false)
bool(true)
resource(%dof type (Unknown)

Warningftell(): %d is not a valid stream resource in %s on line %d
bool
(false)

Warningfeof(): %d is not a valid stream resource in %s on line %d
bool
(false)

-- 
Iteration with mode 'a+b' --
resource(%dof type (stream)
int(0)
bool(false)
bool(true)
resource(%dof type (Unknown)

Warningftell(): %d is not a valid stream resource in %s on line %d
bool
(false)

Warningfeof(): %d is not a valid stream resource in %s on line %d
bool
(false)

-- 
Iteration with mode 'x' --
resource(%dof type (stream)
int(0)
bool(false)
bool(true)
resource(%dof type (Unknown)

Warningftell(): %d is not a valid stream resource in %s on line %d
bool
(false)

Warningfeof(): %d is not a valid stream resource in %s on line %d
bool
(false)
resource(%dof type (Unknown)

-- 
Iteration with mode 'xb' --
resource(%dof type (stream)
int(0)
bool(false)
bool(true)
resource(%dof type (Unknown)

Warningftell(): %d is not a valid stream resource in %s on line %d
bool
(false)

Warningfeof(): %d is not a valid stream resource in %s on line %d
bool
(false)
resource(%dof type (Unknown)

-- 
Iteration with mode 'xt' --
resource(%dof type (stream)
int(0)
bool(false)
bool(true)
resource(%dof type (Unknown)

Warningftell(): %d is not a valid stream resource in %s on line %d
bool
(false)

Warningfeof(): %d is not a valid stream resource in %s on line %d
bool
(false)
resource(%dof type (Unknown)

-- 
Iteration with mode 'x+' --
resource(%dof type (stream)
int(0)
bool(false)
bool(true)
resource(%dof type (Unknown)

Warningftell(): %d is not a valid stream resource in %s on line %d
bool
(false)

Warningfeof(): %d is not a valid stream resource in %s on line %d
bool
(false)
resource(%dof type (Unknown)

-- 
Iteration with mode 'x+b' --
resource(%dof type (stream)
int(0)
bool(false)
bool(true)
resource(%dof type (Unknown)

Warningftell(): %d is not a valid stream resource in %s on line %d
bool
(false)

Warningfeof(): %d is not a valid stream resource in %s on line %d
bool
(false)
resource(%dof type (Unknown)

-- 
Iteration with mode 'x+t' --
resource(%dof type (stream)
int(0)
bool(false)
bool(true)
resource(%dof type (Unknown)

Warningftell(): %d is not a valid stream resource in %s on line %d
bool
(false)

Warningfeof(): %d is not a valid stream resource in %s on line %d
bool
(false)
resource(%dof type (Unknown)

*** 
Done ***