Moved serialize and unserialize to variables.

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@32238 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Ron Chmara 2000-09-08 06:52:30 +00:00
parent f604295b07
commit c0c98e95c2
2 changed files with 109 additions and 109 deletions

View file

@ -762,63 +762,6 @@ $binarydata = pack ("nvc*", 0x1234, 0x5678, 65, 66);
</refsect1>
</refentry>
<refentry id="function.serialize">
<refnamediv>
<refname>serialize</refname>
<refpurpose>
Generates a storable representation of a value
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>serialize</function></funcdef>
<paramdef>mixed <parameter>value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>Serialize</function> returns a string containing a
byte-stream representation of <parameter>value</parameter> that
can be stored anywhere.
</simpara>
<simpara>
This is useful for storing or passing PHP values around without
losing their type and structure.
</simpara>
<simpara>
To make the serialized string into a PHP value again, use
<function>unserialize</function>. <function>Serialize</function>
handles the types <type>integer</type>, <type>double</type>,
<type>string</type>, <type>array</type> (multidimensional) and
<type>object</type> (object properties will be serialized, but
methods are lost).
</simpara>
<para>
<example>
<title><function>Serialize</function> example</title>
<programlisting role="php">
// $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, &amp;$sqldata)) {
$stmt = odbc_prepare($conn,
"INSERT INTO sessions (id, data) VALUES(?, ?)");
if (!odbc_execute($stmt, &amp;$sqldata)) {
/* Something went wrong. Bitch, whine and moan. */
}
}
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.show-source">
<refnamediv>
<refname>show_source</refname>
@ -980,58 +923,6 @@ $array = unpack ("c2chars/nint", $binarydata);
</refsect1>
</refentry>
<refentry id="function.unserialize">
<refnamediv>
<refname>unserialize</refname>
<refpurpose>
Creates a PHP value from a stored representation
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>unserialize</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>unserialize</function> takes a single serialized
variable (see <function>serialize</function>) and converts it
back into a PHP value. The converted value is returned, and can
be an <type>integer</type>, <type>double</type>,
<type>string</type>, <type>array</type> or <type>object</type>.
If an object was serialized, its methods are not preserved in the
returned value.
</simpara>
<para>
<example>
<title><function>Unserialize</function> example</title>
<programlisting role="php">
// Here, we use unserialize() to load session data from a database
// into $session_data. This example complements the one described
// with <function>serialize</function>.
$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, &amp;$sqldata) || !odbc_fetch_into ($stmt, &amp;$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();
}
}
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.usleep">
<refnamediv>
<refname>usleep</refname>

View file

@ -632,6 +632,63 @@ print_r ($a);
</refsect1>
</refentry>
<refentry id="function.serialize">
<refnamediv>
<refname>serialize</refname>
<refpurpose>
Generates a storable representation of a value
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>serialize</function></funcdef>
<paramdef>mixed <parameter>value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>Serialize</function> returns a string containing a
byte-stream representation of <parameter>value</parameter> that
can be stored anywhere.
</simpara>
<simpara>
This is useful for storing or passing PHP values around without
losing their type and structure.
</simpara>
<simpara>
To make the serialized string into a PHP value again, use
<function>unserialize</function>. <function>Serialize</function>
handles the types <type>integer</type>, <type>double</type>,
<type>string</type>, <type>array</type> (multidimensional) and
<type>object</type> (object properties will be serialized, but
methods are lost).
</simpara>
<para>
<example>
<title><function>Serialize</function> example</title>
<programlisting role="php">
// $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, &amp;$sqldata)) {
$stmt = odbc_prepare($conn,
"INSERT INTO sessions (id, data) VALUES(?, ?)");
if (!odbc_execute($stmt, &amp;$sqldata)) {
/* Something went wrong. Bitch, whine and moan. */
}
}
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.settype">
<refnamediv>
<refname>settype</refname>
@ -698,6 +755,58 @@ print_r ($a);
</refsect1>
</refentry>
<refentry id="function.unserialize">
<refnamediv>
<refname>unserialize</refname>
<refpurpose>
Creates a PHP value from a stored representation
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>unserialize</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>unserialize</function> takes a single serialized
variable (see <function>serialize</function>) and converts it
back into a PHP value. The converted value is returned, and can
be an <type>integer</type>, <type>double</type>,
<type>string</type>, <type>array</type> or <type>object</type>.
If an object was serialized, its methods are not preserved in the
returned value.
</simpara>
<para>
<example>
<title><function>Unserialize</function> example</title>
<programlisting role="php">
// Here, we use unserialize() to load session data from a database
// into $session_data. This example complements the one described
// with <function>serialize</function>.
$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, &amp;$sqldata) || !odbc_fetch_into ($stmt, &amp;$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();
}
}
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.unset">
<refnamediv>
<refname>unset</refname>