<?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 => 'ja',
  ),
  'this' => 
  array (
    0 => 'reflectionproperty.getvalue.php',
    1 => 'ReflectionProperty::getValue',
    2 => '値を取得する',
  ),
  'up' => 
  array (
    0 => 'class.reflectionproperty.php',
    1 => 'ReflectionProperty',
  ),
  'prev' => 
  array (
    0 => 'reflectionproperty.gettype.php',
    1 => 'ReflectionProperty::getType',
  ),
  'next' => 
  array (
    0 => 'reflectionproperty.hasdefaultvalue.php',
    1 => 'ReflectionProperty::hasDefaultValue',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'ja',
    'path' => 'reference/reflection/reflectionproperty/getvalue.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="reflectionproperty.getvalue" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ReflectionProperty::getValue</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">ReflectionProperty::getValue</span> &mdash; <span class="dc-title">値を取得する</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-reflectionproperty.getvalue-description">
  <h3 class="title">説明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>ReflectionProperty::getValue</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 class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>): <span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span></div>

  <p class="para rdfs-comment">
   プロパティの値を取得します。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-reflectionproperty.getvalue-parameters">
  <h3 class="title">パラメータ</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">object</code></dt>
     <dd>
      <p class="para">
       static でないプロパティの場合は、プロパティを取得したいオブジェクトを指定しなければなりません。
       オブジェクトを指定せずにデフォルトのプロパティを取得したい場合は、かわりに
       <span class="methodname"><a href="reflectionclass.getdefaultproperties.php" class="methodname">ReflectionClass::getDefaultProperties()</a></span>
       を使います。
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-reflectionproperty.getvalue-returnvalues">
  <h3 class="title">戻り値</h3>
  <p class="para">
   プロパティの現在の値を返します。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-reflectionproperty.getvalue-changelog">
  <h3 class="title">変更履歴</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>バージョン</th>
      <th>説明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.1.0</td>
      <td>
       private と protected なプロパティは
       <span class="methodname"><strong>ReflectionProperty::getValue()</strong></span>
       ですぐにアクセスできるようになりました。
       これより前のバージョンでは、
       <span class="methodname"><a href="reflectionproperty.setaccessible.php" class="methodname">ReflectionProperty::setAccessible()</a></span>
       をコールすることでアクセスできるようにする必要がありました。
       そうしない場合、
       <span class="classname"><a href="class.reflectionexception.php" class="classname">ReflectionException</a></span>
       がスローされていました。
      </td>
     </tr>

     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">object</code> は、nullable になりました。
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-reflectionproperty.getvalue-examples">
  <h3 class="title">例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>例1 <span class="methodname"><strong>ReflectionProperty::getValue()</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: #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">= </span><span style="color: #DD0000">'foobar'</span><span style="color: #007700">;<br />    <br />    public </span><span style="color: #0000BB">$property </span><span style="color: #007700">= </span><span style="color: #DD0000">'barfoo'</span><span style="color: #007700">;<br />    protected </span><span style="color: #0000BB">$privateProperty </span><span style="color: #007700">= </span><span style="color: #DD0000">'foofoo'</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: #0000BB">var_dump</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">)-&gt;</span><span style="color: #0000BB">getValue</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">var_dump</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">'property'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">getValue</span><span style="color: #007700">(new </span><span style="color: #0000BB">Foo</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">// PHP 8.1.0 より前のバージョンのみ、この行の実行が必須でした<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">(new </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>上の例の出力は以下となります。</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">string(6) &quot;foobar&quot;
string(6) &quot;barfoo&quot;
string(6) &quot;foofoo&quot;</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-reflectionproperty.getvalue-seealso">
  <h3 class="title">参考</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="methodname"><a href="reflectionproperty.setvalue.php" class="methodname" rel="rdfs-seeAlso">ReflectionProperty::setValue()</a> - プロパティの値を設定する</span></li>
    <li><span class="methodname"><a href="reflectionproperty.setaccessible.php" class="methodname" rel="rdfs-seeAlso">ReflectionProperty::setAccessible()</a> - プロパティのアクセス範囲を設定する</span></li>
    <li><span class="methodname"><a href="reflectionclass.getdefaultproperties.php" class="methodname" rel="rdfs-seeAlso">ReflectionClass::getDefaultProperties()</a> - デフォルトプロパティを取得する</span></li>
    <li><span class="methodname"><a href="reflectionclass.getstaticpropertyvalue.php" class="methodname" rel="rdfs-seeAlso">ReflectionClass::getStaticPropertyValue()</a> - staticプロパティの値を取得する</span></li>
   </ul>
  </p>
 </div>


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