unserialize
unserialize
Creates a PHP value from a stored representation
mixed **unserialize** string $data array $options
takes a single serialized variable and
converts it back into a PHP value.
unserialize
Waarschuwing: > Do not pass untrusted user input to regardless of the value of . Unserialization can result in code being loaded and executed due to object instantiation and autoloading, and a malicious user may be able to exploit this. Use a safe, standard data interchange format such as JSON (via and ) if you need to pass serialized data to the user.
unserialize``options``allowed_classes``json_decode``json_encodeIf you need to unserialize externally-stored serialized data, consider using for data validation. Make sure data is not modified by anyone but you.
hash_hmac
dataThe serialized string.
If the variable being unserialized is an object, after successfully
reconstructing the object PHP will automatically attempt to call the
or methods (if one exists).
__unserialize()__wakeup()
> **Opmerking:** > ### unserialize_callback_func
directive The callback specified in the directive is called when an undefined class is unserialized. If no callback is specified, the object will be instantiated as . unserialize_callback_func`__PHP_Incomplete_Class`
options
Any options to be provided to , as an
associative array.
unserialize
The converted value is returned, and can be a ,
, , ,
or .
bool``int``float``string``array``object
In case the passed string is not unserializeable, false is returned and
is issued.
E_WARNING
Objects may throw s in their unserialization handlers.
Throwable
As of PHP 8.4.0, if the element of
is not an of class names,
throws s
and s.
allowed_classes``options``array``unserialize
Voorbeeld: example
<?php
// Here, we use unserialize() to load session data to the
// $session_data array from the string selected from a database.
// This example complements the one described with serialize().
$conn = odbc_connect("webdb", "php", "chicken");
$stmt = odbc_prepare($conn, "SELECT data FROM sessions WHERE id = ?");
$sqldata = array($_SERVER['PHP_AUTH_USER']);
if (!odbc_execute($stmt, $sqldata) || !odbc_fetch_into($stmt, $tmp)) {
// if the execute or fetch fails, initialize to empty array
$session_data = array();
} else {
// we should now have the serialized data in $tmp[0].
$session_data = unserialize($tmp[0]);
if (!is_array($session_data)) {
// something went wrong, initialize to empty array
$session_data = array();
}
}
?>
Voorbeeld: unserialize_callback_func example
<?php
$serialized_object='O:1:"a":1:{s:5:"value";s:3:"100";}';
ini_set('unserialize_callback_func', 'mycallback'); // set your callback_function
function mycallback($classname)
{
// just include a file containing your class definition
// you get $classname to figure out which class definition is required
var_dump($classname);
}
unserialize($serialized_object);
?>
Waarschuwing: > false is returned both in the case of an error and if unserializing the serialized false value. It is possible to catch this special case by comparing with or by catching the issued .
data``serialize(false)``E_WARNING
json_encode``json_decode``hash_hmac``serializeAutoloading Classesunserialize_callback_funcunserialize_max_depth__wakeup()__serialize()__unserialize()