<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.reflectionproperty.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'reflectionproperty.setvalue.php',
    1 => 'ReflectionProperty::setValue',
    2 => 'Set property value',
  ),
  'up' => 
  array (
    0 => 'class.reflectionproperty.php',
    1 => 'ReflectionProperty',
  ),
  'prev' => 
  array (
    0 => 'reflectionproperty.setrawvaluewithoutlazyinitialization.php',
    1 => 'ReflectionProperty::setRawValueWithoutLazyInitialization',
  ),
  'next' => 
  array (
    0 => 'reflectionproperty.skiplazyinitialization.php',
    1 => 'ReflectionProperty::skipLazyInitialization',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/reflection/reflectionproperty/setvalue.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="reflectionproperty.setvalue" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ReflectionProperty::setValue</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">ReflectionProperty::setValue</span> &mdash; <span class="dc-title">Set property value</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-reflectionproperty.setvalue-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>ReflectionProperty::setValue</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.object.php" class="type object">object</a></span></span> <code class="parameter">$object</code></span>, <span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>): <span class="type"><a href="language.types.void.php" class="type void">void</a></span></div>

  <div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><strong>ReflectionProperty::setValue</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>): <span class="type"><a href="language.types.void.php" class="type void">void</a></span></div>

  <p class="para rdfs-comment">
   Sets (changes) the property&#039;s value.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <span class="simpara">
    To set static property values, use <code class="literal">ReflectionProperty::setValue(null, $value)</code>.
   </span>
  </p></blockquote>
 </div>

 
 <div class="refsect1 parameters" id="refsect1-reflectionproperty.setvalue-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">object</code></dt>
     <dd>
      <p class="para">
       For static properties, pass in <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>.
       For non-static properties, pass in the object.
      </p>
     </dd>
    
    
     <dt><code class="parameter">value</code></dt>
     <dd>
      <p class="para">
       The new value.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-reflectionproperty.setvalue-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   No value is returned.
  </p>
 </div>

 
 <div class="refsect1 changelog" id="refsect1-reflectionproperty.setvalue-changelog">
  <h3 class="title">Changelog</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Description</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.3.0</td>
      <td>
       Calling this method with a single argument is deprecated,
       instead use <code class="literal">ReflectionProperty::setValue(null, $value)</code>
       for static properties.
      </td>
     </tr>

     <tr>
      <td>8.1.0</td>
      <td>
       Private and protected properties can be accessed by
       <span class="methodname"><strong>ReflectionProperty::setValue()</strong></span> right away.
       Previously, they needed to be made accessible by calling
       <span class="methodname"><a href="reflectionproperty.setaccessible.php" class="methodname">ReflectionProperty::setAccessible()</a></span>; otherwise
       a <span class="classname"><a href="class.reflectionexception.php" class="classname">ReflectionException</a></span> was thrown.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-reflectionproperty.setvalue-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="methodname"><strong>ReflectionProperty::setValue()</strong></span> example</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">Foo </span><span style="color: #007700">{<br />    public static </span><span style="color: #0000BB">$staticProperty</span><span style="color: #007700">;<br />    <br />    public </span><span style="color: #0000BB">$property</span><span style="color: #007700">;<br />    protected </span><span style="color: #0000BB">$privateProperty</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">$reflectionClass </span><span style="color: #007700">= new </span><span style="color: #0000BB">ReflectionClass</span><span style="color: #007700">(</span><span style="color: #DD0000">'Foo'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// As of PHP 8.3, passing in null as the first argument is required<br />// to access static properties.<br /></span><span style="color: #0000BB">$reflectionProperty </span><span style="color: #007700">= </span><span style="color: #0000BB">$reflectionClass</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getProperty</span><span style="color: #007700">(</span><span style="color: #DD0000">'staticProperty'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$reflectionProperty</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setValue</span><span style="color: #007700">(</span><span style="color: #0000BB">null</span><span style="color: #007700">, </span><span style="color: #DD0000">'foo'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">Foo</span><span style="color: #007700">::</span><span style="color: #0000BB">$staticProperty</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$foo </span><span style="color: #007700">= new </span><span style="color: #0000BB">Foo</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$reflectionClass</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getProperty</span><span style="color: #007700">(</span><span style="color: #DD0000">'property'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">setValue</span><span style="color: #007700">(</span><span style="color: #0000BB">$foo</span><span style="color: #007700">, </span><span style="color: #DD0000">'bar'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$foo</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">property</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$reflectionProperty </span><span style="color: #007700">= </span><span style="color: #0000BB">$reflectionClass</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getProperty</span><span style="color: #007700">(</span><span style="color: #DD0000">'privateProperty'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$reflectionProperty</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setAccessible</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">); </span><span style="color: #FF8000">// only required prior to PHP 8.1.0<br /></span><span style="color: #0000BB">$reflectionProperty</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setValue</span><span style="color: #007700">(</span><span style="color: #0000BB">$foo</span><span style="color: #007700">, </span><span style="color: #DD0000">'foobar'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$reflectionProperty</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getValue</span><span style="color: #007700">(</span><span style="color: #0000BB">$foo</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">string(3) &quot;foo&quot;
string(3) &quot;bar&quot;
string(6) &quot;foobar&quot;</pre>
</div>
    </div>
   </div>
  </p>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-reflectionproperty.setvalue-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="methodname"><a href="reflectionproperty.getvalue.php" class="methodname" rel="rdfs-seeAlso">ReflectionProperty::getValue()</a> - Gets value</span></li>
    <li><span class="methodname"><a href="reflectionproperty.setaccessible.php" class="methodname" rel="rdfs-seeAlso">ReflectionProperty::setAccessible()</a> - Set property accessibility</span></li>
    <li><span class="methodname"><a href="reflectionclass.setstaticpropertyvalue.php" class="methodname" rel="rdfs-seeAlso">ReflectionClass::setStaticPropertyValue()</a> - Sets public static property value</span></li>
   </ul>
  </p>
 </div>

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