Anonymous user / 3.12.36.130 Log In Register |
?
Wallet:
3.00
Daily Credits:
1.20 / 1.20
|
PHP Functions Online
Description #
Parameters #
- str
The serialized string.
If the variable being unserialized is an object, after successfully reconstructing the object PHP will automatically attempt to call the __wakeup() member function (if it exists).
Note: unserialize_callback_func directive
It's possible to set a callback-function which will be called, if an undefined class should be instantiated during unserializing. (to prevent getting an incomplete object "__PHP_Incomplete_Class".) Use your php.ini, ini_set() or .htaccess to define 'unserialize_callback_func'. Everytime an undefined class should be instantiated, it'll be called. To disable this feature just empty this setting.
Return Values #
Examples #
Example #1 unserialize() 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();
}
}
?>
Changelog #
Version | Description |
---|---|
4.2.0 | The directive unserialize_callback_func became available. |
Notes #
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 str
with
serialize(false) or by catching the issued
E_NOTICE
.
Do not pass untrusted user input to unserialize(). 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 json_decode() and json_encode()) if you need to pass serialized data to the user.
See Also #
- Main PHP Function Online page
- serialize() - Generates a storable representation of a value
- Autoloading Objects
- unserialize_callback_func
- __wakeup()