gisostallenberg / curlfile-serializer
serialize and unserialize a CURLFile
Package info
github.com/gisostallenberg/curlfile-serializer
pkg:composer/gisostallenberg/curlfile-serializer
Requires
- imnotjames/curlfile-compat: ^0.0.1
Requires (Dev)
- phpunit/phpunit: ^5.7
Suggests
None
Provides
None
Conflicts
None
Replaces
None
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
Serializableinterface, which is deprecated as of PHP 8.1 and slated for removal: it emits a deprecation notice today and will eventually stop working. Itsunserialize()also doesextract(unserialize($data))— injecting variables into local scope, and running a nestedunserialize()with noallowed_classesguard (an object-injection footgun if the blob is ever untrusted).There is no alternative package, and you cannot serialize a
CURLFiledirectly 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