Search by

gisostallenberg / curlfile-serializer

gisostallenberg

This package is abandoned and no longer maintained. No replacement package was suggested.

serialize and unserialize a CURLFile

Package info

github.com/gisostallenberg/curlfile-serializer

pkg:composer/gisostallenberg/curlfile-serializer

Statistics

Installs: 242

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2017-02-09 15:58 UTC

This package is auto-updated.

Last update: 2026-10-27 20:51:22 UTC


README

Serialize and unserialize a CURLFile

⚠️ Avoid in new code

This package implements the Serializable interface, which is deprecated as of PHP 8.1 and slated for removal: it emits a deprecation notice today and will eventually stop working. Its unserialize() also does extract(unserialize($data)) — injecting variables into local scope, and running a nested unserialize() with no allowed_classes guard (an object-injection footgun if the blob is ever untrusted).

There is no alternative package, and you cannot serialize a CURLFile directly either — PHP forbids that since 7.4. The job is only round-tripping its three strings, so store those and rebuild the object. On a wrapper class, use the modern __serialize()/__unserialize() magic methods (PHP 7.4+) — no package needed:

public function __serialize(): array
{
    return [
        $this->curlfile->getFileName(),
        $this->curlfile->getMimeType(),
        $this->curlfile->getPostFilename(),
    ];
}

public function __unserialize(array $data): void
{
    [$name, $mime, $postname] = $data;
    $this->curlfile = new CURLFile($name, $mime, $postname);
}

Or skip the wrapper entirely and persist the three strings yourself. Note that moving to the magic methods changes the stored format, so treat it as a breaking change for any already-persisted data.

Installation

composer require gisostallenberg/curlfile-serializer

Usage example

<?php

use GisoStallenberg\CURLFileSerializer\CURLFileSerializer;

$curlFileSerializer = CURLFileSerializer::create(new CURLFile('/path/to/file.txt'));
$serialized = serialize($curlFileSerializer);

$curlFileSerializer = unserialize($serialized);
$curlFile = $curlFileSerializer->getCURLFile(); // Is an instanceof CURLFile