PHP sandbox
PHP unserialize() Online
Paste a serialized string and see the PHP value it turns into, with types, notices and the exact error offset. Runs on real PHP 8.2 on our server when you press Run.
About unserialize()
unserialize() turns a string produced by serialize() back into a PHP value. The format is compact and typed: i:1; is an integer, b:0; is false, s:5:"Alice"; is a five-byte string and a:2:{...} is an array with two elements.
This sandbox always passes allowed_classes => false, so no class is ever loaded or constructed. Serialized objects come back as __PHP_Incomplete_Class, and the original class name is kept in the __PHP_Incomplete_Class_Name property.
A failed unserialize returns false and raises a notice with the byte offset where parsing stopped. The serialized value b:0; also returns false, but with no notice. The result panel shows the difference.
Worked example
$data = 'a:2:{s:1:"a";i:1;s:1:"b";b:1;}';
var_dump(unserialize($data, ['allowed_classes' => false]));
// array(2) {
// ["a"]=>
// int(1)
// ["b"]=>
// bool(true)
// }var_dump(unserialize('s:5:"abc";'));
// Notice: unserialize(): Error at offset 10 of 10 bytes
// bool(false)The declared length (5) must match the byte length of the string. Multi-byte characters count as several bytes.
Frequently asked questions
Why does unserialize() say "Error at offset"?
The string does not follow the serialize format at that byte. The usual causes are a wrong s:N length after editing a string by hand, a changed character encoding, or a truncated database column.
How do I tell a failure from a serialized false?
Both return false. A failure also raises an E_NOTICE, so check for the notice, or compare the input with serialize(false), which is b:0;.
Is unserialize() safe on user input?
Not with classes allowed: crafted objects can trigger magic methods. Use allowed_classes => false, or better, use JSON for data from users.
Is my input sent to a server?
Yes. These pages run real PHP 8.2 on the w3docs server, so the text you enter is sent there to run, in a sandbox with no network access. Do not paste passwords, keys or personal data.
How much input can I send?
Up to 6,000 bytes across all text fields, which is about 6,000 characters of plain text (accented letters and emoji take 2 to 4 bytes). Larger input is refused before anything is sent.