Sophie

Sophie

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

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

<HTML
><HEAD
><TITLE
>unserialize</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="strval"
HREF="function.strval.html"><LINK
REL="NEXT"
TITLE="unset"
HREF="function.unset.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.strval.html"
ACCESSKEY="P"
>Anterior</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.unset.html"
ACCESSKEY="N"
>Siguiente</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.unserialize"
></A
>unserialize</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN78734"
></A
><P
>    (PHP 3&#62;= 3.0.5, PHP 4 )</P
>unserialize&nbsp;--&nbsp;
     Creates a PHP value from a stored representation
    </DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN78737"
></A
><H2
>Description</H2
>mixed <B
CLASS="methodname"
>unserialize</B
> ( string str [, string callback])<BR
></BR
><P
>&#13;     <B
CLASS="function"
>unserialize()</B
> takes a single serialized
     variable (see <A
HREF="function.serialize.html"
><B
CLASS="function"
>serialize()</B
></A
>) and converts it
     back into a PHP value.  The converted value is returned, and can
     be an <A
HREF="language.types.html#language.types.integer"
><B
CLASS="type"
>integer</B
></A
>, <A
HREF="language.types.float.html"
><B
CLASS="type"
>float</B
></A
>,
     <A
HREF="language.types.string.html"
><B
CLASS="type"
>string</B
></A
>, <A
HREF="language.types.array.html"
><B
CLASS="type"
>array</B
></A
> or <A
HREF="language.types.object.html"
><B
CLASS="type"
>object</B
></A
>.
     In case the passed string is not unserializeable, <TT
CLASS="constant"
><B
>FALSE</B
></TT
> is returned.
    </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>unserialize_callback_func directive: </B
>
      It's possible to set a callback-function which will be called,
      if an undefined class should be instantiated during unserializing.
      (to prevent getting an incomplete <A
HREF="language.types.object.html"
><B
CLASS="type"
>object</B
></A
> "__PHP_Incomplete_Class".)
      Use your <TT
CLASS="filename"
>php.ini</TT
>, <A
HREF="function.ini-set.html"
><B
CLASS="function"
>ini_set()</B
></A
> or <TT
CLASS="filename"
>.htaccess</TT
> 
      to define 'unserialize_callback_func'.  Everytime an undefined class
      should be instantiated, it'll be called.  To disable this feature just
      empty this setting.  Also note that the directive
      unserialize_callback_func directive became 
      available in PHP 4.2.0. 
     </P
></BLOCKQUOTE
></DIV
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Nota: </B
>
     The <TT
CLASS="parameter"
><I
>callback</I
></TT
> parameter was added in PHP 4.2.0
     </P
></BLOCKQUOTE
></DIV
><P
>&#13;     If the variable being unserialized is an object, after successfully 
     reconstructing the object PHP will automatically attempt to call the
     <B
CLASS="function"
>__wakeup()</B
> member function (if it exists). 
     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN78769"
></A
><P
><B
>Ejemplo 1. unserialize_callback_func example</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>&#60;?php
$serialized_object='O:1:"a":1:{s:5:"value";s:3:"100";}';

// unserialize_callback_func directive available as of PHP 4.2.0
ini_set('unserialize_callback_func','mycallback'); // set your callback_function

function mycallback($classname) {
    // just include a file containing your classdefinition
    // you get $classname to figure out which classdefinition is required
}
?&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
    </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Nota: </B
>
      In PHP 3, methods are not preserved when unserializing a
      serialized object. 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
> or 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="AEN78777"
></A
><P
><B
>Ejemplo 2. <B
CLASS="function"
>unserialize()</B
> example</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>&#60;?php
// Here, we use unserialize() to load session data to the
// $session_data array from the string selected from a database.
// 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, &#38;$sqldata) || !odbc_fetch_into ($stmt, &#38;$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();
    }
}
?&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
    </P
><P
>&#13;    See Also: <A
HREF="function.serialize.html"
><B
CLASS="function"
>serialize()</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.strval.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.unset.html"
ACCESSKEY="N"
>Siguiente</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>strval</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"
>unset</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>