SplFileObject::__construct
(PHP 5 >= 5.1.0)
SplFileObject::__construct — Construct a new file object.
설명
Construct a new file object.
인수
- filename
-
The file to read.
Tipfopen 래퍼를 활성화하면, 파일명으로 URL을 사용할 수 있습니다. 파일 이름을 지정하는 방법은 fopen()을 참고하십시오. 다양한 래퍼의 기능, 사용법, 제공하는 예약 정의 변수들에 대해서는 Supported Protocols and Wrappers를 참고하십시오.
- 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;
}
?>
