CVS update: php3/doc/functions
| From: | ssb | Date: | Fri, 23 Oct 1998 11:35:45 +0000 |
| Subject: | CVS update: php3/doc/functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-1985@lists.php.net to get a copy of this message | ||
Date: Friday October 23, 1998 @ 7:35
Author: ssb
Update of /repository/php3/doc/functions
In directory asf:/u2/tmp/cvs-serv9574
Modified Files:
misc.sgml
Log Message:
hm, the serialize() and unserialize() docs were not commited
Index: php3/doc/functions/misc.sgml
diff -c php3/doc/functions/misc.sgml:1.6 php3/doc/functions/misc.sgml:1.7
*** php3/doc/functions/misc.sgml:1.6 Sat Sep 26 05:36:43 1998
--- php3/doc/functions/misc.sgml Fri Oct 23 07:35:44 1998
***************
*** 64,70 ****
</refsect1>
</refentry>
-
<refentry id="function.leak">
<refnamediv>
<refname>leak</refname>
--- 64,69 ----
***************
*** 84,90 ****
</refsect1>
</refentry>
! <refentry id="function.register-shutdown-function">
<refnamediv>
<refname>register_shutdown_function</refname>
<refpurpose>Register a function for execution on shutdown.</refpurpose>
--- 83,89 ----
</refsect1>
</refentry>
! <refentry id="function.register-shutdown-function">
<refnamediv>
<refname>register_shutdown_function</refname>
<refpurpose>Register a function for execution on shutdown.</refpurpose>
***************
*** 101,106 ****
--- 100,154 ----
</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>
+ <funcdef>string <function>serialize</function></funcdef>
+ <paramdef>mixed <parameter>value</parameter></paramdef>
+ </funcsynopsis>
+ <simpara>
+ <function>serialize</function> returns a string containing a
+ byte-stream representation of <parameter>value</parameter> that
+ can be stored anywhere.
+ <simpara>
+ This is useful for storing or passing PHP values around without
+ losing their type and structure.
+ <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).
+ <para>
+ <example>
+ <title>serialize 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, &$sqldata)) {
+ $stmt = odbc_prepare($conn,
+ "INSERT INTO sessions (id, data) VALUES(?, ?)");
+ if (!odbc_execute($stmt, &$sqldata)) {
+ /* Something went wrong. Bitch, whine and moan. */
+ }
+ }
+ </programlisting>
+ </example>
+ </refsect1>
+ </refentry>
+
<refentry id="function.sleep">
<refnamediv>
<refname>sleep</refname>
***************
*** 120,141 ****
</refsect1>
</refentry>
! <refentry id="function.usleep">
<refnamediv>
! <refname>usleep</refname>
! <refpurpose>Delay execution in microseconds</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
! <funcdef>void <function>usleep</function></funcdef>
! <paramdef>int <parameter>micro_seconds</parameter></paramdef>
</funcsynopsis>
<simpara>
! The sleep function delays program execution for the given number
! of <parameter>micro_seconds</parameter>.
! <simpara>
! See also <function>sleep</function>.
</refsect1>
</refentry>
--- 168,216 ----
</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>
! <funcdef>mixed <function>unserialize</function></funcdef>
! <paramdef>string <parameter>str</parameter></paramdef>
</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.
! <para>
! <example>
! <title>unserialize 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, &$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();
! }
! }
! </programlisting>
! </example>
</refsect1>
</refentry>
***************
*** 156,161 ****
--- 231,255 ----
generate identifiers simultaneously on several hosts that might happen to
generate the identifier at the same microsecond. The prefix can be up to 114
characters long.
+ </refsect1>
+ </refentry>
+
+ <refentry id="function.usleep">
+ <refnamediv>
+ <refname>usleep</refname>
+ <refpurpose>Delay execution in microseconds</refpurpose>
+ </refnamediv>
+ <refsect1>
+ <title>Description</title>
+ <funcsynopsis>
+ <funcdef>void <function>usleep</function></funcdef>
+ <paramdef>int <parameter>micro_seconds</parameter></paramdef>
+ </funcsynopsis>
+ <simpara>
+ The sleep function delays program execution for the given number
+ of <parameter>micro_seconds</parameter>.
+ <simpara>
+ See also <function>sleep</function>.
</refsect1>
</refentry>
--
PHP Development Mailing List http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
For help: php-dev-help@lists.php.net