<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.classobj.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'ja',
  ),
  'this' => 
  array (
    0 => 'function.method-exists.php',
    1 => 'method_exists',
    2 => 'クラスメソッドが存在するかどうかを確認する',
  ),
  'up' => 
  array (
    0 => 'ref.classobj.php',
    1 => 'クラス/オブジェクト関数',
  ),
  'prev' => 
  array (
    0 => 'function.is-subclass-of.php',
    1 => 'is_subclass_of',
  ),
  'next' => 
  array (
    0 => 'function.property-exists.php',
    1 => 'property_exists',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'ja',
    'path' => 'reference/classobj/functions/method-exists.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.method-exists" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">method_exists</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">method_exists</span> &mdash; <span class="dc-title">クラスメソッドが存在するかどうかを確認する</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.method-exists-description">
  <h3 class="title">説明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>method_exists</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="language.types.object.php" class="type object">object</a></span>|<span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$object_or_class</code></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$method</code></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   指定した <code class="parameter">object_or_class</code> にクラスメソッドが存在するかどうかを調べます。
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.method-exists-parameters">
  <h3 class="title">パラメータ</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">object_or_class</code></dt>
     <dd>
      <p class="para">
       オブジェクトのインスタンス、あるいはクラス名。
      </p>
     </dd>
    
    
     <dt><code class="parameter">method</code></dt>
     <dd>
      <p class="para">
       メソッドの名前。
      </p>
     </dd>
    
   </dl>
  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.method-exists-returnvalues">
  <h3 class="title">戻り値</h3>
  <p class="para">
   <code class="parameter">method</code> で指定したメソッドが
   指定した <code class="parameter">object_or_class</code> において定義されている場合に
   <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>、そうでない場合に <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> を返します。
  </p>
 </div>


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

    </thead>

    <tbody class="tbody">
     <tr>
      <td>7.4.0</td>
      <td>
       継承した private メソッドに対してこの関数を実行しても、
       <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> を返すようになりました。
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.method-exists-examples">
  <h3 class="title">例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>例1 <span class="function"><strong>method_exists()</strong></span> の例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$directory </span><span style="color: #007700">= new </span><span style="color: #0000BB">Directory</span><span style="color: #007700">(</span><span style="color: #DD0000">'.'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">method_exists</span><span style="color: #007700">(</span><span style="color: #0000BB">$directory</span><span style="color: #007700">,</span><span style="color: #DD0000">'read'</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="examplescode"><pre class="examplescode">bool(true)</pre>
</div>
    </div>
   </div>
   <div class="example" id="example-2">
    <p><strong>例2 staticメソッドに対する <span class="function"><strong>method_exists()</strong></span> の例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">method_exists</span><span style="color: #007700">(</span><span style="color: #DD0000">'Directory'</span><span style="color: #007700">,</span><span style="color: #DD0000">'read'</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="examplescode"><pre class="examplescode">bool(true)</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.method-exists-notes">
  <h3 class="title">注意</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
<p class="para">この関数を使うと、未知のクラスに対しては登録済みの
<a href="language.oop5.autoload.php" class="link">autoloader</a> を使用します。</p></p></blockquote>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <span class="simpara">
    マジックメソッド <a href="language.oop5.overloading.php#language.oop5.overloading.methods" class="link"><code class="literal">__call</code></a> を使ってアクセス可能なメソッドを、<span class="function"><strong>method_exists()</strong></span> は検知できません。
   </span>
  </p></blockquote>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-function.method-exists-seealso">
  <h3 class="title">参考</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.function-exists.php" class="function" rel="rdfs-seeAlso">function_exists()</a> - 指定した関数が定義されている場合に true を返す</span></li>
    <li><span class="function"><a href="function.is-callable.php" class="function" rel="rdfs-seeAlso">is_callable()</a> - 引数が、現在のスコープから関数としてコール可能な値かどうかを調べる</span></li>
    <li><span class="function"><a href="function.class-exists.php" class="function" rel="rdfs-seeAlso">class_exists()</a> - クラスが定義済みかどうかを確認する</span></li>
   </ul>
  </p>
 </div>

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