SplFileObject
SplFileObject::current
SplFileObject
PHP Manual

# SplFileObject::__construct

(PHP 5 >= 5.1.0)

SplFileObject::__construct — Construct a new file object.

### 설명

SplFileObject::__construct ( string `$filename` [, string `$open_mode`= "r" [, bool `$use_include_path`= false [, resource `$context` ]]] )

Construct a new file object.

### 인수

`filename`

  The file to read.

  Tip

  fopen 래퍼를 활성화하면, 파일명으로 URL을 사용할 수 있습니다. 파일 이름을 지정하는 방법은 fopen()을, 지원하는 URL 프로토콜 목록은 지원 프로토콜/래퍼 목록를 참고하십시오.

`open_mode`

  The mode in which to open the file. See fopen() for a list of allowed modes.

`use_include_path`

  Whether to search in the include_path for `filename` .

`context`

  A valid context resource created with stream_context_create().

### 반환값

값을 반환하지 않습니다.

### 오류/예외

Throws a RuntimeException if the `filename` cannot be opened.

### 예제

Example #1 SplFileObject::__construct example

This example opens the current file and iterates over its contents line by line.

`<?php
$file = new SplFileObject(__FILE__);
foreach ($file as $line) {
echo $line;
}
?>`

위 예제의 출력 예시:

    <?php
    $file = new SplFileObject(__FILE__);
    foreach ($file as $line) {
        echo $line;
    }
    ?>

### 참고

- SplFileInfo::openFile - Gets an SplFileObject object for the file
- fopen() - Opens file or URL

SplFileObject
SplFileObject::current
SplFileObject
PHP Manual