From c0c98e95c2c207d6d7febb7b2fe68b58c0c0e06a Mon Sep 17 00:00:00 2001 From: Ron Chmara Date: Fri, 8 Sep 2000 06:52:30 +0000 Subject: [PATCH] Moved serialize and unserialize to variables. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@32238 c90b9560-bf6c-de11-be94-00142212c4b1 --- functions/misc.xml | 109 --------------------------------------------- functions/var.xml | 109 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+), 109 deletions(-) diff --git a/functions/misc.xml b/functions/misc.xml index bb55db20a0..c3caf7c878 100644 --- a/functions/misc.xml +++ b/functions/misc.xml @@ -762,63 +762,6 @@ $binarydata = pack ("nvc*", 0x1234, 0x5678, 65, 66); - - - serialize - - Generates a storable representation of a value - - - - Description - - - string serialize - mixed value - - - - Serialize returns a string containing a - byte-stream representation of value that - can be stored anywhere. - - - This is useful for storing or passing PHP values around without - losing their type and structure. - - - To make the serialized string into a PHP value again, use - unserialize. Serialize - handles the types integer, double, - string, array (multidimensional) and - object (object properties will be serialized, but - methods are lost). - - - - <function>Serialize</function> example - -// $session_data contains a multi-dimensional array with session -// information for the current user. We use serialize() to store -// it in a database at the end of the request. - -$conn = odbc_connect ("webdb", "php", "chicken"); -$stmt = odbc_prepare ($conn, - "UPDATE sessions SET data = ? WHERE id = ?"); -$sqldata = array (serialize($session_data), $PHP_AUTH_USER); -if (!odbc_execute ($stmt, &$sqldata)) { - $stmt = odbc_prepare($conn, - "INSERT INTO sessions (id, data) VALUES(?, ?)"); - if (!odbc_execute($stmt, &$sqldata)) { - /* Something went wrong. Bitch, whine and moan. */ - } -} - - - - - - show_source @@ -980,58 +923,6 @@ $array = unpack ("c2chars/nint", $binarydata); - - - unserialize - - Creates a PHP value from a stored representation - - - - Description - - - mixed unserialize - string str - - - - unserialize takes a single serialized - variable (see serialize) and converts it - back into a PHP value. The converted value is returned, and can - be an integer, double, - string, array or object. - If an object was serialized, its methods are not preserved in the - returned value. - - - - <function>Unserialize</function> example - -// Here, we use unserialize() to load session data from a database -// into $session_data. 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 ($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(); - } -} - - - - - - usleep diff --git a/functions/var.xml b/functions/var.xml index aa1695b31f..61b2f010ba 100644 --- a/functions/var.xml +++ b/functions/var.xml @@ -632,6 +632,63 @@ print_r ($a); + + + serialize + + Generates a storable representation of a value + + + + Description + + + string serialize + mixed value + + + + Serialize returns a string containing a + byte-stream representation of value that + can be stored anywhere. + + + This is useful for storing or passing PHP values around without + losing their type and structure. + + + To make the serialized string into a PHP value again, use + unserialize. Serialize + handles the types integer, double, + string, array (multidimensional) and + object (object properties will be serialized, but + methods are lost). + + + + <function>Serialize</function> example + +// $session_data contains a multi-dimensional array with session +// information for the current user. We use serialize() to store +// it in a database at the end of the request. + +$conn = odbc_connect ("webdb", "php", "chicken"); +$stmt = odbc_prepare ($conn, + "UPDATE sessions SET data = ? WHERE id = ?"); +$sqldata = array (serialize($session_data), $PHP_AUTH_USER); +if (!odbc_execute ($stmt, &$sqldata)) { + $stmt = odbc_prepare($conn, + "INSERT INTO sessions (id, data) VALUES(?, ?)"); + if (!odbc_execute($stmt, &$sqldata)) { + /* Something went wrong. Bitch, whine and moan. */ + } +} + + + + + + settype @@ -698,6 +755,58 @@ print_r ($a); + + + unserialize + + Creates a PHP value from a stored representation + + + + Description + + + mixed unserialize + string str + + + + unserialize takes a single serialized + variable (see serialize) and converts it + back into a PHP value. The converted value is returned, and can + be an integer, double, + string, array or object. + If an object was serialized, its methods are not preserved in the + returned value. + + + + <function>Unserialize</function> example + +// Here, we use unserialize() to load session data from a database +// into $session_data. 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 ($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(); + } +} + + + + + + unset