SplFileObject::__construct

(PHP 5 >= 5.1.0, PHP 7, PHP 8)

SplFileObject::__constructConstruct a new file object

Beschreibung

public SplFileObject::__construct(
    string $filename,
    string $mode = "r",
    bool $useIncludePath = false,
    ?resource $context = null
)

Construct a new file object.

Parameter-Liste

filename

The file to read.

Tipp

Wenn fopen wrappers aktiviert ist, kann mit dieser Funktion eine URL als Dateiname verwendet werden. Mehr Details dazu, wie der Dateiname angeben werden muss, sind bei fopen() zu finden. Eine Liste der unterstützten URL-Protokolle, die Fähigkeiten der verschiedenen Wrapper, Hinweise zu deren Verwendung und Informationen zu den eventuell vorhandenen vordefinierten Variablen sind unter Unterstützte Protokolle und Wrapper zu finden.

mode

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

useIncludePath

Whether to search in the include_path for filename.

context

A valid context resource created with stream_context_create().

Fehler/Exceptions

Throws a RuntimeException if the filename cannot be opened.

Throws a LogicException if the filename is a directory.

Beispiele

Beispiel #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_num => $line) {
    echo 
"Line $line_num is $line";
}
?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

Line 0 is <?php
Line 1 is $file = new SplFileObject(__FILE__);
Line 2 is foreach ($file as $line_num => $line) {
Line 3 is     echo "Line $line_num is $line";
Line 4 is }
Line 5 is ?>

Siehe auch

Hier Kannst Du einen Kommentar verfassen


Bitte gib mindestens 10 Zeichen ein.
Wird geladen... Bitte warte.
* Pflichtangabe
Es sind noch keine Kommentare vorhanden.

Was genau bedeutet "Vibe Coding"? Ein tiefgehender Blick für Entwickler

In der Welt der Softwareentwicklung gibt es unzählige Wege, wie man an ein Projekt herangeht. Manche schwören auf strikte Planung, andere auf bewährte Algorithmen und wieder andere lassen sich von etwas ganz anderem leiten: ihrem Gefühl. ...

admin

Autor : admin
Kategorie: Software & Web-Development

PHP cURL-Tutorial: Verwendung von cURL zum Durchführen von HTTP-Anfragen

cURL ist eine leistungsstarke PHP-Erweiterung, die es Ihnen ermöglicht, mit verschiedenen Servern über verschiedene Protokolle wie HTTP, HTTPS, FTP und mehr zu kommunizieren. ...

TheMax

Autor : TheMax
Kategorie: PHP-Tutorials

Midjourney Tutorial - Anleitung für Anfänger

Über Midjourney, dem Tool zur Erstellung digitaler Bilder mithilfe von künstlicher Intelligenz, gibt es ein informatives Video mit dem Titel "Midjourney Tutorial auf Deutsch - Anleitung für Anfänger" ...

Mike94

Autor : Mike94
Kategorie: KI Tutorials

Tutorial veröffentlichen

Tutorial veröffentlichen

Teile Dein Wissen mit anderen Entwicklern weltweit

Du bist Profi in deinem Bereich und möchtest dein Wissen teilen, dann melde dich jetzt an und teile es mit unserer PHP-Community

mehr erfahren

Tutorial veröffentlichen

Problem with Game Script

jacksonmark Respect—you're only 21 and a half years late

Geschrieben von scatello am 17.04.2026 12:47:19
Forum: PHP Developer Forum
Problem with Game Script

It sounds like you're having trouble with the game script. Here are a few quick tips: Check Login Details: Make sure you're entering the correct ...

Geschrieben von jacksonmark am 17.04.2026 11:28:27
Forum: PHP Developer Forum
u4gm Why Arc Raiders Feels So Good With a Real Team

Arc Raiders doesn't look like another sci-fi shooter you burn through in a weekend and forget. From what's been shown so far, it feels built aroun ...

Geschrieben von luissuraez798 am 17.04.2026 09:51:13
Forum: PHP Developer Forum
u4gm Where MLB The Show 26 Really Comes Alive

There's a reason this series still sets the pace for baseball sims. MLB The Show 26 gets the feel of the sport right, from the slow burn of a tens ...

Geschrieben von luissuraez798 am 17.04.2026 09:50:36
Forum: News / Kostenloses