zendframework/zend-serializer
zendframework/zend-serializer provides flexible object and data serialization for PHP, with interchangeable adapters (e.g., PHP serialize, JSON) plus options, filtering, and error handling. Useful for caching, storage, and transporting structured data safely.
This package provides basic serialization support (e.g., JSON, PHP, XML) for legacy Zend Framework 2 applications or standalone components still relying on the zendframework namespace. Begin by installing via Composer:
composer require zendframework/zend-serializer
Note: The package is archived and unmaintained since 2019. For modern apps, prefer symfony/serializer, nesbot/serializer, or native json_encode/decode.
First use case: serialize a simple PHP array to JSON:
use Zend\Serializer\Serializer;
$data = ['user' => 'alice', 'role' => 'admin'];
$json = Serializer::serialize($data, 'json');
// $json === '{"user":"alice","role":"admin"}'
Json, Php, Xml) via the factory or static methods for different formats:
use Zend\Serializer\Adapter\AdapterInterface;
use Zend\Serializer\Serializer;
$serializer = new Serializer\Adapter\Json();
$serialized = $serializer->serialize($data);
'service_manager' => [
'factories' => [
'Serializer' => Serializer\SerializerServiceFactory::class,
],
],
serialize()/unserialize() but wrapped in consistent API:
$unserialized = Serializer::unserialize($jsonString, 'json');
composer show zendframework/zend-serializer and plan migration.Zend\Serializer\* (not Laminas\Serializer\*). Migrating to Laminas is recommended: laminas/laminas-serializer.Php adapter with untrusted input — unserialize() can lead to RCE. Prefer Json.jsonOptions vs json_options) silently ignore or break serialization.Adapter\AdapterInterface to add custom formats, but be aware: no backward compatibility guarantees are provided post-archive.var_dump(Serializer::getAdapter('json')->getOptions()) to inspect runtime adapter config, especially when behavior mismatches docs.How can I help you explore Laravel packages today?