Phar::offsetSet

(PHP 5 >= 5.3.0, PHP 7, PHP 8, PECL phar >= 1.0.0)

Phar::offsetSetSet the contents of an internal file to those of an external file

Beschreibung

public Phar::offsetSet(string $localName, resource|string $value): void

Hinweis:

Diese Methode des Phar-Objekts funktioniert nur wenn die php.ini-Einstellung phar.readonly auf 0 gesetzt ist, sonst wird eine PharException geworfen.

This is an implementation of the ArrayAccess interface allowing direct manipulation of the contents of a Phar archive using array access brackets. offsetSet is used for modifying an existing file, or adding a new file to a Phar archive.

Parameter-Liste

localName

The filename (relative path) to modify in a Phar.

value

Content of the file.

Rückgabewerte

No return values.

Fehler/Exceptions

if phar.readonly is 1, BadMethodCallException is thrown, as modifying a Phar is only allowed when phar.readonly is set to 0. Throws PharException if there are any problems flushing changes made to the Phar archive to disk.

Beispiele

Beispiel #1 A Phar::offsetSet() example

offsetSet should not be accessed directly, but instead used via array access with the [] operator.

<?php
$p 
= new Phar('/path/to/my.phar'0'my.phar');
try {
    
// calls offsetSet
    
$p['file.txt'] = 'Hi there';
} catch (
Exception $e) {
    echo 
'Could not modify file.txt:'$e;
}
?>

Anmerkungen

Hinweis: Die Funktionen Phar::addFile(), Phar::addFromString() und Phar::offsetSet() speichern bei jedem Aufruf ein neues phar-Archiv. Wenn die Leistung ein wichtiger Faktor ist, sollte stattdessen Phar::buildFromDirectory() oder Phar::buildFromIterator() verwendet werden.

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

PHP session lost after AJAX reload

Hi everyone, I’m running into a strange issue with PHP sessions in my project. I have a login system that works fine on normal page loads, but ...

Geschrieben von mikasabaggins am 20.04.2026 07:02:03
Forum: PHP Developer Forum
IGGM | Diablo 4: Lord of Hatred Copies Giveaway + Prep Event

The next expansion for Diablo IV — Lord of Hatred — arrives on April 28, bringing with it a massive wave of new content, character builds, and ...

Geschrieben von Cjacker am 20.04.2026 04:01:19
Forum: Apps und PHP Script Gesuche
IGGM April Offers 8% Off ARC Raiders Flashpoint Blueprints

Hey, Raiders! Did ARC Raiders Flashpoint Update live up to your expectations? Let me share my thoughts first: Flashpoint Update seems to have cran ...

Geschrieben von Cjacker am 20.04.2026 03:55:53
Forum: Apps und PHP Script Gesuche
IGGM: Buying Cheap MLB The Show 26 Stubs | All Platform | Live Update Price

I believe every MLB The Show 26 player dreams of assembling an invincible Diamond Dynasty lineup; however, a lack of sufficient Stubs - the game's ...

Geschrieben von Cjacker am 20.04.2026 03:50:21
Forum: Apps und PHP Script Gesuche