<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.var.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'function.unserialize.php',
    1 => 'unserialize',
    2 => 'Crea un valore PHP a partire da una rappresentazione archiviata',
  ),
  'up' => 
  array (
    0 => 'ref.var.php',
    1 => 'Variable handling Funzioni',
  ),
  'prev' => 
  array (
    0 => 'function.strval.php',
    1 => 'strval',
  ),
  'next' => 
  array (
    0 => 'function.unset.php',
    1 => 'unset',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'it',
    'path' => 'reference/var/functions/unserialize.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.unserialize" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">unserialize</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">unserialize</span> &mdash; <span class="dc-title">
   Crea un valore PHP a partire da una rappresentazione archiviata
  </span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.unserialize-description">
  <h3 class="title">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>unserialize</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$str</code></span>): <span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span></div>

  <p class="simpara">
   La funzione <span class="function"><strong>unserialize()</strong></span> prende il formato serializzato di
   una variabile (vedere <span class="function"><a href="function.serialize.php" class="function">serialize()</a></span>) e la riporta al valore PHP.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.unserialize-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">str</code></dt>
     <dd>
      <p class="para">
       La stringa serializzata.
      </p>
      <p class="para">
       Se la variabile da ripristinare è un oggetto, dopo avere ricostruito
       l&#039;oggetto, il PHP cercherà di eseguire la funzione membro 
       <span class="function"><strong>__wakeup()</strong></span> (se esiste).
      </p>
      <p class="para">
       <blockquote class="note"><p><strong class="note">Nota</strong>: 
        <strong>Direttiva unserialize_callback_func</strong><br />
        <p class="para">
         E&#039; possibile impostare una funzione di callback che possa essere richiamata
         se, durante la fase di deserializzazione, occorre istanziare una classe indefinita.
         (per evitare di ottenere un tipo <span class="type"><a href="language.types.object.php" class="type object">object</a></span> incompleto &quot;__PHP_Incomplete_Class&quot;.)
         Per definire il parametro &#039;unserialize_callback_func&#039; si può agire sul
         <var class="filename">php.ini</var>, o usare <span class="function"><a href="function.ini-set.php" class="function">ini_set()</a></span> oppure con <var class="filename">.htaccess</var>.
         Verrà utilizzata questa funzione ogni volta che occorre istanziare una classe indefinita.
         Per disabilitare questa opzione, lasciare vuota questa impostazione.
        </p>
       </p></blockquote>
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.unserialize-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="para">
   Il valore convertito è restituito, e può essere un <span class="type"><a href="language.types.boolean.php" class="type boolean">boolean</a></span>,
   <span class="type"><a href="language.types.integer.php" class="type integer">integer</a></span>, <span class="type"><a href="language.types.float.php" class="type float">float</a></span>, <span class="type"><a href="language.types.string.php" class="type string">string</a></span>,
   <span class="type"><a href="language.types.array.php" class="type array">array</a></span> oppure <span class="type"><a href="language.types.object.php" class="type object">object</a></span>.
  </p>
  <p class="para">
   Nel caso in cui la stringa passata non sia deserializzabile la funzione restituisce <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> e genera
   un <strong><code><a href="errorfunc.constants.php#constant.e-notice">E_NOTICE</a></code></strong>.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.unserialize-changelog">
  <h3 class="title">Log delle modifiche</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Versione</th>
       <th>Descrizione</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>4.2.0</td>
       <td>
        La direttiva unserialize_callback_func è disponibile.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.unserialize-examples">
  <h3 class="title">Esempi</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 Esempio di uso di <span class="function"><strong>unserialize()</strong></span></strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// In questo esempio si usa unserialize() per caricare i dati nell'array<br />// $session_data dalla stringa estratta da un database.<br />// Questo esempio è complementare a quello descritto in serialize().<br /><br /></span><span style="color: #0000BB">$conn </span><span style="color: #007700">= </span><span style="color: #0000BB">odbc_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"webdb"</span><span style="color: #007700">, </span><span style="color: #DD0000">"php"</span><span style="color: #007700">, </span><span style="color: #DD0000">"chicken"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$stmt </span><span style="color: #007700">= </span><span style="color: #0000BB">odbc_prepare</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">, </span><span style="color: #DD0000">"SELECT data FROM sessions WHERE id = ?"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$sqldata </span><span style="color: #007700">= array(</span><span style="color: #0000BB">$_SERVER</span><span style="color: #007700">[</span><span style="color: #DD0000">'PHP_AUTH_USER'</span><span style="color: #007700">]);<br />if (!</span><span style="color: #0000BB">odbc_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">, </span><span style="color: #0000BB">$sqldata</span><span style="color: #007700">) || !</span><span style="color: #0000BB">odbc_fetch_into</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">, </span><span style="color: #0000BB">$tmp</span><span style="color: #007700">)) {<br />    </span><span style="color: #FF8000">// se odbc_execute o odbc_fetch_into generano un errore, si predispone un array vuoto<br />    </span><span style="color: #0000BB">$session_data </span><span style="color: #007700">= array();<br />} else {<br />    </span><span style="color: #FF8000">// ora abbiamo i dati serializzati in $tmp[0].<br />    </span><span style="color: #0000BB">$session_data </span><span style="color: #007700">= </span><span style="color: #0000BB">unserialize</span><span style="color: #007700">(</span><span style="color: #0000BB">$tmp</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]);<br />    if (!</span><span style="color: #0000BB">is_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$session_data</span><span style="color: #007700">)) {<br />       </span><span style="color: #FF8000">// qualcosa non ha funzionato, si predispone un array vuoto<br />       </span><span style="color: #0000BB">$session_data </span><span style="color: #007700">= array();<br />    }<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2">
    <p><strong>Example #2 Esempio di unserialize_callback_func</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$serialized_object</span><span style="color: #007700">=</span><span style="color: #DD0000">'O:1:"a":1:{s:5:"value";s:3:"100";}'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// direttiva unserialize_callback_func disponibile da PHP 4.2.0<br /></span><span style="color: #0000BB">ini_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'unserialize_callback_func'</span><span style="color: #007700">, </span><span style="color: #DD0000">'mycallback'</span><span style="color: #007700">); </span><span style="color: #FF8000">// imposta la callback_function<br /><br /></span><span style="color: #007700">function </span><span style="color: #0000BB">mycallback</span><span style="color: #007700">(</span><span style="color: #0000BB">$classname</span><span style="color: #007700">) <br />{<br />    </span><span style="color: #FF8000">// includere un file contenente la definizione di classe<br />    // $classname indica la classe da usare<br /></span><span style="color: #007700">}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.unserialize-notes">
  <h3 class="title">Note</h3>
  <div class="warning"><strong class="warning">Avviso</strong>
   <p class="para">
    <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> è restituito sia in caso di errore e sia in caso di de-serializzazione 
    del valore <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>. Questo caso particolare può essere intercettato
    confrontando <code class="parameter">str</code> con
    <code class="literal">serialize(false)</code> o rilevando il 
    <strong><code><a href="errorfunc.constants.php#constant.e-notice">E_NOTICE</a></code></strong> generato.
   </p>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.unserialize-seealso">
  <h3 class="title">Vedere anche:</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.serialize.php" class="function" rel="rdfs-seeAlso">serialize()</a> - Genera una versione archiviabile del valore</span></li>
    <li><a href="language.oop5.autoload.php" class="link">Autoloading Objects</a></li>
    <li><a href="var.configuration.php#unserialize-callback-func" class="link">unserialize_callback_func</a></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>