Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > by-pkgid > a34ed6838d4b29d38abd504392a4a797 > files > 2387

php-manual-es-4.3.0-2mdk.noarch.rpm

<HTML
><HEAD
><TITLE
>serialize</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="Manual de PHP"
HREF="index.html"><LINK
REL="UP"
TITLE="Funciones sobre variables"
HREF="ref.variables.html"><LINK
REL="PREVIOUS"
TITLE="print_r"
HREF="function.print-r.html"><LINK
REL="NEXT"
TITLE="settype"
HREF="function.settype.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=ISO-8859-1"></HEAD
><BODY
CLASS="refentry"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Manual de PHP</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.print-r.html"
ACCESSKEY="P"
>Anterior</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.settype.html"
ACCESSKEY="N"
>Siguiente</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.serialize"
></A
>serialize</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN78639"
></A
><P
>    (PHP 3&#62;= 3.0.5, PHP 4 )</P
>serialize&nbsp;--&nbsp;
     Generates a storable representation of a value
    </DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN78642"
></A
><H2
>Description</H2
>string <B
CLASS="methodname"
>serialize</B
> ( mixed value)<BR
></BR
><P
>&#13;     <B
CLASS="function"
>serialize()</B
> returns a string containing a
     byte-stream representation of <TT
CLASS="parameter"
><I
>value</I
></TT
> that
     can be stored anywhere.
    </P
><P
>&#13;     This is useful for storing or passing PHP values around without
     losing their type and structure.
    </P
><P
>&#13;    To make the serialized string into a PHP value again, use
    <A
HREF="function.unserialize.html"
><B
CLASS="function"
>unserialize()</B
></A
>.  <B
CLASS="function"
>serialize()</B
>
    handles all types, except the resource-type.
    You can even <B
CLASS="function"
>serialize()</B
> arrays that contain
    references to itself. References inside the array/object you 
    are <B
CLASS="function"
>serialize()</B
>ing will also be stored.
   </P
><P
>&#13;   When serializing objects, PHP will attempt to call the member function
   <B
CLASS="function"
>__sleep()</B
> prior to serialization. This is to allow the
   object to do any last minute clean-up, etc. prior to being serialized.
   Likewise, when the object is restored using <A
HREF="function.unserialize.html"
><B
CLASS="function"
>unserialize()</B
></A
>
   the <B
CLASS="function"
>__wakeup()</B
> member function is called.
   </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Nota: </B
>
     In PHP 3, object properties will be serialized, but methods are
     lost.  PHP 4 removes that limitation and restores both properties
     and methods.  Please see the <A
HREF="missing-stuff.html#language.oop.serialization"
>Serializing Objects</A
>
     section of <A
HREF="language.oop.html"
>Classes and
     Objects</A
> for more information.
    </P
></BLOCKQUOTE
></DIV
><P
>&#13;     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN78669"
></A
><P
><B
>Ejemplo 1. <B
CLASS="function"
>serialize()</B
> example</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="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, &#38;$sqldata)) {
    $stmt = odbc_prepare($conn,
     "INSERT INTO sessions (id, data) VALUES(?, ?)");
    if (!odbc_execute($stmt, &#38;$sqldata)) {
    /* Something went wrong.  Bitch, whine and moan. */
    }
}</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
    </P
><P
>&#13;    See Also: <A
HREF="function.unserialize.html"
><B
CLASS="function"
>unserialize()</B
></A
>.
   </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.print-r.html"
ACCESSKEY="P"
>Anterior</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Inicio</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.settype.html"
ACCESSKEY="N"
>Siguiente</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>print_r</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.variables.html"
ACCESSKEY="U"
>Subir</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>settype</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>