Sophie

Sophie

distrib > Mandriva > 2008.1 > i586 > by-pkgid > 703d980c580707c382b4e43e25965bc5 > files > 9530

php-manual-pt_BR-5.2.4-1mdv2008.1.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>serialize</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="Manual do PHP"
HREF="index.html"><LINK
REL="UP"
TITLE="Variáveis, Funções"
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=UTF-8"></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 do 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"
>Próxima</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.serialize"
></A
>serialize</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN230374"
></A
><P
>    (PHP 3 &#62;= 3.0.5, PHP 4, PHP 5)</P
>serialize&nbsp;--&nbsp;
     Generates a storable representation of a value
    </DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN230377"
></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 <CODE
CLASS="parameter"
>value</CODE
> 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 <A
HREF="language.types.resource.html"
><B
CLASS="type"
>resource</B
></A
>-type.
    You can even <B
CLASS="function"
>serialize()</B
> arrays that contain
    references to itself. Circular references inside the array/object you 
    are <B
CLASS="function"
>serialize()</B
>ing will also be stored. Any other 
    reference will be lost.
   </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
>
     This didn't work correctly until 4.0.7.
    </P
></BLOCKQUOTE
></DIV
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Nota: </B
>
     In PHP 3, object properties will be serialized, but methods are
     lost.  That limitation was removed in PHP 4 as both properties
     and methods are now restored.  Please see the <A
HREF="language.oop.serialization.html"
>Serializing Objects</A
>
     section of <A
HREF="language.oop.html"
>Classes and
     Objects</A
> for more information.
    </P
><P
>&#13;     It is not possible to serialize PHP built-in objects.
    </P
></BLOCKQUOTE
></DIV
><P
>&#13;     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN230407"
></A
><P
><B
>Exemplo 1. <B
CLASS="function"
>serialize()</B
> example</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br /></font><font color="#FF8000">// $session_data contains a multi-dimensional array with session<br />// information for the current user.&nbsp;&nbsp;We use serialize() to store<br />// it in a database at the end of the request.<br /><br /></font><font color="#0000BB">$conn </font><font color="#007700">= </font><font color="#0000BB">odbc_connect</font><font color="#007700">(</font><font color="#DD0000">"webdb"</font><font color="#007700">, </font><font color="#DD0000">"php"</font><font color="#007700">, </font><font color="#DD0000">"chicken"</font><font color="#007700">);<br /></font><font color="#0000BB">$stmt </font><font color="#007700">= </font><font color="#0000BB">odbc_prepare</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">"UPDATE sessions SET data = ? WHERE id = ?"</font><font color="#007700">);<br /></font><font color="#0000BB">$sqldata </font><font color="#007700">= array (</font><font color="#0000BB">serialize</font><font color="#007700">(</font><font color="#0000BB">$session_data</font><font color="#007700">), </font><font color="#0000BB">$PHP_AUTH_USER</font><font color="#007700">);<br />if (!</font><font color="#0000BB">odbc_execute</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">, &amp;</font><font color="#0000BB">$sqldata</font><font color="#007700">)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$stmt </font><font color="#007700">= </font><font color="#0000BB">odbc_prepare</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">"INSERT INTO sessions (id, data) VALUES(?, ?)"</font><font color="#007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;if (!</font><font color="#0000BB">odbc_execute</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">, &amp;</font><font color="#0000BB">$sqldata</font><font color="#007700">)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">/* Something went wrong.. */<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">}<br />}<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></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"
>Principal</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.settype.html"
ACCESSKEY="N"
>Próxima</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"
>Acima</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>settype</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>