<?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.newlazyproxy.php',
    1 => 'ReflectionClass::newLazyProxy',
    2 => 'Cr&eacute;er une nouvelle instance proxy paresseuse',
  ),
  'up' => 
  array (
    0 => 'class.reflectionclass.php',
    1 => 'ReflectionClass',
  ),
  'prev' => 
  array (
    0 => 'reflectionclass.newlazyghost.php',
    1 => 'ReflectionClass::newLazyGhost',
  ),
  'next' => 
  array (
    0 => 'reflectionclass.resetaslazyghost.php',
    1 => 'ReflectionClass::resetAsLazyGhost',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'reference/reflection/reflectionclass/newlazyproxy.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

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

 </div>

 <div class="refsect1 description" id="refsect1-reflectionclass.newlazyproxy-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>ReflectionClass::newLazyProxy</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.callable.php" class="type callable">callable</a></span> <code class="parameter">$factory</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 proxy paresseuse de la classe, en attachant la
   <code class="parameter">factory</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. Lorsqu&#039;une
   tentative est faite d&#039;observer ou de modifier l&#039;état du proxy pour la première
   fois, la fonction fabrique est appelée pour fournir une instance réelle, qui
   est ensuite attachée au proxy. Après cela, toutes les interactions ultérieures
   avec le proxy sont transmises à l&#039;instance réelle. 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.newlazyproxy-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <dl>
   
    <dt><code class="parameter">factory</code></dt>
    <dd>
     <span class="simpara">
      La fabrique est une fonction de rappel avec la signature suivante:
     </span>
     <p class="para">
      <div class="methodsynopsis dc-description">
       <span class="methodname"><span class="replaceable">factory</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.object.php" class="type object">object</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 point,
          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 fabrique doit renvoyer un objet, appelé <em>instance réelle</em>,
      qui est ensuite attaché au proxy. Cette instance réelle ne doit pas être paresseuse
      et ne doit pas être le proxy lui-même. Si l&#039;instance réelle n&#039;a pas la même classe
      que le proxy, la classe du proxy doit être une sous-classe de la classe de l&#039;instance
      réelle, sans propriétés supplémentaires, et ne doit pas remplacer les méthodes
      <span class="methodname"><strong>__destruct()</strong></span> ou <span class="methodname"><strong>__clone()</strong></span>.
      methods.
     </span>
    </dd>
   
   
    <dt><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.newlazyproxy-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="simpara">
   Renvoie une instance proxy 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.newlazyproxy-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.newlazyproxy-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 /></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">newLazyProxy</span><span style="color: #007700">(function (</span><span style="color: #0000BB">Example $object</span><span style="color: #007700">) {<br />     </span><span style="color: #0000BB">$realInstance </span><span style="color: #007700">= new </span><span style="color: #0000BB">Example</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br />     return </span><span style="color: #0000BB">$realInstance</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 transmet la récupération de la propriété à l'instance réelle  <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">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$object</span><span style="color: #007700">);<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 proxy object(Example)#3 (0) {
  [&quot;prop&quot;]=&gt;
  uninitialized(int)
}
bool(true)
Example::__construct
int(1)
lazy proxy object(Example)#3 (1) {
  [&quot;instance&quot;]=&gt;
  object(Example)#4 (1) {
    [&quot;prop&quot;]=&gt;
    int(1)
  }
}</pre>
</div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-reflectionclass.newlazyproxy-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.newlazyghost.php" class="methodname" rel="rdfs-seeAlso">ReflectionClass::newLazyGhost()</a> - Cr&eacute;er une nouvelle instance fant&ocirc;me 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.resetaslazyproxy.php" class="methodname" rel="rdfs-seeAlso">ReflectionClass::resetAsLazyProxy()</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); ?>