The SplFileObject class

Introduction

The SplFileObject class offers an object-oriented interface for a file.

Class synopsis

SplFileObject
extends SplFileInfo
implements RecursiveIterator SeekableIterator
/* Constants */
public const int SplFileObject::DROP_NEW_LINE;
public const int SplFileObject::READ_AHEAD;
public const int SplFileObject::SKIP_EMPTY;
public const int SplFileObject::READ_CSV;
/* Methods */
public SplFileObject::__construct(
    string $filename,
    string $mode = "r",
    bool $useIncludePath = false,
    resourcenull $context = null
)
public stringarrayfalse SplFileObject::current()
public bool SplFileObject::eof()
public bool SplFileObject::fflush()
public stringfalse SplFileObject::fgetc()
public arrayfalse SplFileObject::fgetcsv(string $separator = ",", string $enclosure = "\"", string $escape = "\\")
public string SplFileObject::fgets()
public string SplFileObject::fgetss(string $allowable_tags = ?)
public bool SplFileObject::flock(int $operation, int &$wouldBlock = null)
public int SplFileObject::fpassthru()
public intfalse SplFileObject::fputcsv(
    array $fields,
    string $separator = ",",
    string $enclosure = "\"",
    string $escape = "\\",
    string $eol = "\n"
)
public stringfalse SplFileObject::fread(int $length)
public arrayintnull SplFileObject::fscanf(string $format, mixed &...$vars)
public int SplFileObject::fseek(int $offset, int $whence = SEEK_SET)
public array SplFileObject::fstat()
public intfalse SplFileObject::ftell()
public bool SplFileObject::ftruncate(int $size)
public intfalse SplFileObject::fwrite(string $data, int $length = 0)
public null SplFileObject::getChildren()
public array SplFileObject::getCsvControl()
public int SplFileObject::getFlags()
public int SplFileObject::getMaxLineLen()
public false SplFileObject::hasChildren()
public int SplFileObject::key()
public void SplFileObject::next()
public void SplFileObject::rewind()
public void SplFileObject::seek(int $line)
public void SplFileObject::setCsvControl(string $separator = ",", string $enclosure = "\"", string $escape = "\\")
public void SplFileObject::setFlags(int $flags)
public void SplFileObject::setMaxLineLen(int $maxLength)
public string SplFileObject::__toString()
public bool SplFileObject::valid()
/* Inherited methods */
public intfalse getATime()
public string getBasename(string $suffix = "")
public intfalse getCTime()
public string getExtension()
public SplFileInfo getFileInfo(stringnull $class = null)
public string getFilename()
public intfalse getGroup()
public intfalse getInode()
public stringfalse getLinkTarget()
public intfalse getMTime()
public intfalse getOwner()
public string getPath()
public SplFileInfonull getPathInfo(stringnull $class = null)
public string getPathname()
public intfalse getPerms()
public stringfalse getRealPath()
public intfalse getSize()
public stringfalse getType()
public bool isDir()
public bool isExecutable()
public bool isFile()
public bool isLink()
public bool isReadable()
public bool isWritable()
public SplFileObject openFile(string $mode = "r", bool $useIncludePath = false, resourcenull $context = null)
public void setFileClass(string $class = SplFileObject::class)
public void setInfoClass(string $class = SplFileInfo::class)
public string __toString()

Predefined Constants

SplFileObject::DROP_NEW_LINE

Drop newlines at the end of a line.

SplFileObject::READ_AHEAD

Read on rewind/next.

SplFileObject::SKIP_EMPTY

Skips empty lines in the file. This requires the READ_AHEAD flag be enabled, to work as expected.

SplFileObject::READ_CSV

Read lines as CSV rows.

Table of Contents