<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.reflectionclass.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'fr',
  ),
  'this' => 
  array (
    0 => 'reflectionclass.newlazyghost.php',
    1 => 'ReflectionClass::newLazyGhost',
    2 => 'Cr&eacute;er une nouvelle instance fant&ocirc;me paresseuse',
  ),
  'up' => 
  array (
    0 => 'class.reflectionclass.php',
    1 => 'ReflectionClass',
  ),
  'prev' => 
  array (
    0 => 'reflectionclass.newinstancewithoutconstructor.php',
    1 => 'ReflectionClass::newInstanceWithoutConstructor',
  ),
  'next' => 
  array (
    0 => 'reflectionclass.newlazyproxy.php',
    1 => 'ReflectionClass::newLazyProxy',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'reference/reflection/reflectionclass/newlazyghost.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="reflectionclass.newlazyghost" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ReflectionClass::newLazyGhost</h1>
  <p class="verinfo">(PHP 8 &gt;= 8.4.0)</p><p class="refpurpose"><span class="refname">ReflectionClass::newLazyGhost</span> &mdash; <span class="dc-title">Créer une nouvelle instance fantôme paresseuse</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-reflectionclass.newlazyghost-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>ReflectionClass::newLazyGhost</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.callable.php" class="type callable">callable</a></span> <code class="parameter">$initializer</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$options</code><span class="initializer"> = 0</span></span>): <span class="type"><a href="language.types.object.php" class="type object">object</a></span></div>

  <p class="simpara">
   Crée une nouvelle instance fantôme paresseuse de la classe, en attachant
   l&#039;<code class="parameter">initializer</code> à celle-ci. Le constructeur n&#039;est pas
   appelé, et les propriétés ne sont pas définies à leur valeur par défaut.
   Cependant, l&#039;objet sera automatiquement initialisé en invoquant
   l&#039;<code class="parameter">initializer</code> la première fois que son état est observé
   ou modifié. Voir
   <a href="language.oop5.lazy-objects.php#language.oop5.lazy-objects.initialization-triggers" class="link">déclencheurs
   d&#039;initialisation</a> et <a href="language.oop5.lazy-objects.php#language.oop5.lazy-objects.initialization-sequence" class="link">
   séquence d&#039;initialisation</a>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-reflectionclass.newlazyghost-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <dl>
   
    <dt><code class="parameter">initializer</code></dt>
    <dd>
     <span class="simpara">
      L&#039;initialiseur est une fonction de rappel avec la signature suivante:
     </span>
     <p class="para">
      <div class="methodsynopsis dc-description">
       <span class="methodname"><span class="replaceable">initializer</span></span>(<span class="methodparam"><span class="type"><a href="language.types.object.php" class="type object">object</a></span> <code class="parameter">$object</code></span>): <span class="type"><a href="language.types.void.php" class="type void">void</a></span></div>

      <dl>
       
        <dt><code class="parameter">object</code></dt>
        <dd>
         <span class="simpara">
          L&#039;<code class="parameter">object</code> en cours d&#039;initialisation. À ce stade,
          l&#039;objet n&#039;est plus marqué comme paresseux, et y accéder ne déclenche
          plus l&#039;initialisation.
         </span>
        </dd>
       
      </dl>
     </p>
     <span class="simpara">
      La fonction <code class="parameter">initializer</code> doit renvoyer <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> ou ne
      rien renvoyer.
     </span>
    </dd>
   
   
    <dt id="reflectionclass.newlazyghost.parameters.options"><code class="parameter">options</code></dt>
    <dd>
     <p class="para">
      <code class="parameter">options</code> peut être une combinaison des drapeaux
      suivants:
      <dl>
       
        <dt>
         <strong><code><a href="class.reflectionclass.php#reflectionclass.constants.skip-initialization-on-serialize">ReflectionClass::SKIP_INITIALIZATION_ON_SERIALIZE</a></code></strong>
        </dt>
        <dd>
         <span class="simpara">
          Par défaut, la sérialisation d&#039;un objet paresseux déclenche son
          initialisation. Définir ce drapeau empêche l&#039;initialisation, permettant
          aux objets paresseux d&#039;être sérialisés sans être initialisés.
         </span>
        </dd>
       
      </dl>
     </p>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-reflectionclass.newlazyghost-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="simpara">
   Renvoie une instance fantôme paresseuse. Si l&#039;objet n&#039;a pas de propriétés,
   ou si toutes ses propriétés sont statiques ou virtuelles, une instance normale
   (non paresseuse) est renvoyée. Voir aussi
   <a href="language.oop5.lazy-objects.php#language.oop5.lazy-objects.lifecycle" class="link">Cycle de vie des objets
   paresseux</a>.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-reflectionclass.newlazyghost-errors">
  <h3 class="title">Erreurs / Exceptions</h3>
  <p class="simpara">
   Une <span class="classname"><a href="class.reflectionexception.php" class="classname">ReflectionException</a></span> si la classe est interne ou
   étend une classe interne, sauf <span class="classname"><a href="class.stdclass.php" class="classname">stdClass</a></span>.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-reflectionclass.newlazyghost-examples">
  <h3 class="title">Exemples</h3>
  <div class="example" id="example-1">
   <p><strong>Exemple #1 Utilisation basique</strong></p>
   <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">class </span><span style="color: #0000BB">Example </span><span style="color: #007700">{<br />    public function </span><span style="color: #0000BB">__construct</span><span style="color: #007700">(public </span><span style="color: #0000BB">int $prop</span><span style="color: #007700">) {<br />        echo </span><span style="color: #0000BB">__METHOD__</span><span style="color: #007700">, </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />    }<br />}<br /><br /></span><span style="color: #0000BB">$reflector </span><span style="color: #007700">= new </span><span style="color: #0000BB">ReflectionClass</span><span style="color: #007700">(</span><span style="color: #0000BB">Example</span><span style="color: #007700">::class);<br /></span><span style="color: #0000BB">$object </span><span style="color: #007700">= </span><span style="color: #0000BB">$reflector</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">newLazyGhost</span><span style="color: #007700">(function (</span><span style="color: #0000BB">Example $object</span><span style="color: #007700">) {<br />     </span><span style="color: #0000BB">$object</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">__construct</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br />});<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$object</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$object </span><span style="color: #007700">instanceof </span><span style="color: #0000BB">Example</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Déclenche l'initialisation, et récupère la propriété après cela<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$object</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">prop</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>L&#039;exemple ci-dessus va afficher :</p></div>
   <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">lazy ghost object(Example)#3 (0) {
  [&quot;prop&quot;]=&gt;
  uninitialized(int)
}
bool(true)
Example::__construct
int(1)</pre>
</div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-reflectionclass.newlazyghost-seealso">
  <h3 class="title">Voir aussi</h3>
  <ul class="simplelist">
   <li><a href="language.oop5.lazy-objects.php" class="link">Objet paresseux</a></li>
   <li><span class="methodname"><a href="reflectionclass.newlazyproxy.php" class="methodname" rel="rdfs-seeAlso">ReflectionClass::newLazyProxy()</a> - Cr&eacute;er une nouvelle instance proxy paresseuse</span></li>
   <li><span class="methodname"><a href="reflectionclass.newinstancewithoutconstructor.php" class="methodname" rel="rdfs-seeAlso">ReflectionClass::newInstanceWithoutConstructor()</a> - Cr&eacute;e une nouvelle instance de la classe sans invoquer le constructeur</span></li>
   <li><span class="methodname"><a href="reflectionclass.resetaslazyghost.php" class="methodname" rel="rdfs-seeAlso">ReflectionClass::resetAsLazyGhost()</a> - R&eacute;initialise un objet et le marque comme paresseux</span></li>
   <li><span class="methodname"><a href="reflectionclass.marklazyobjectasinitialized.php" class="methodname" rel="rdfs-seeAlso">ReflectionClass::markLazyObjectAsInitialized()</a> - Marque un objet paresseux comme initialis&eacute; sans appeler l'initialiseur ou la fabrique</span></li>
   <li><span class="methodname"><a href="reflectionclass.initializelazyobject.php" class="methodname" rel="rdfs-seeAlso">ReflectionClass::initializeLazyObject()</a> - Force l'initialisation d'un objet paresseux</span></li>
   <li><span class="methodname"><a href="reflectionclass.isuninitializedlazyobject.php" class="methodname" rel="rdfs-seeAlso">ReflectionClass::isUninitializedLazyObject()</a> - V&eacute;rifie si un objet est paresseux et non initialis&eacute;</span></li>
   <li><span class="methodname"><a href="reflectionproperty.setrawvaluewithoutlazyinitialization.php" class="methodname" rel="rdfs-seeAlso">ReflectionProperty::setRawValueWithoutLazyInitialization()</a> - D&eacute;finit la valeur brute d'une propri&eacute;t&eacute; sans d&eacute;clencher l'initialisation paresseuse</span></li>
   <li><span class="methodname"><a href="reflectionproperty.skiplazyinitialization.php" class="methodname" rel="rdfs-seeAlso">ReflectionProperty::skipLazyInitialization()</a> - Marque une propri&eacute;t&eacute; comme non paresseuse</span></li>
   <li><span class="methodname"><a href="reflectionproperty.islazy.php" class="methodname" rel="rdfs-seeAlso">ReflectionProperty::isLazy()</a> - V&eacute;rifie si une propri&eacute;t&eacute; est paresseuse</span></li>
  </ul>
 </div>


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