<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.var.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'es',
  ),
  'this' => 
  array (
    0 => 'function.is-callable.php',
    1 => 'is_callable',
    2 => 'Determina si un valor puede ser llamado como una funci&oacute;n
   en el &aacute;mbito actual',
  ),
  'up' => 
  array (
    0 => 'ref.var.php',
    1 => 'Funciones de manejo de variables',
  ),
  'prev' => 
  array (
    0 => 'function.is-bool.php',
    1 => 'is_bool',
  ),
  'next' => 
  array (
    0 => 'function.is-countable.php',
    1 => 'is_countable',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'es',
    'path' => 'reference/var/functions/is-callable.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.is-callable" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">is_callable</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.6, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">is_callable</span> &mdash; <span class="dc-title">
   Determina si un valor puede ser llamado como una función
   en el ámbito actual
  </span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.is-callable-description">
  <h3 class="title">Descripción</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>is_callable</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="methodparam"><span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> <code class="parameter">$syntax_only</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong></span></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter reference">&$callable_name</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.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   Verifica que <code class="parameter">value</code> es un <span class="type"><a href="language.types.callable.php" class="type callable">callable</a></span>,
   o que puede ser llamado utilizando la función
   <span class="function"><a href="function.call-user-func.php" class="function">call_user_func()</a></span>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.is-callable-parameters">
  <h3 class="title">Parámetros</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">value</code></dt>
     <dd>
      <p class="para">
       El valor a verificar.
      </p>
     </dd>
    
    
     <dt><code class="parameter">syntax_only</code></dt>
     <dd>
      <p class="para">
       Si el argumento <code class="parameter">syntax_only</code> vale <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>, la
       función solo verificará si <code class="parameter">value</code> puede ser
       una función o un método. Rechazará todos los valores
       que no sean objetos <a href="language.oop5.magic.php#object.invoke" class="link">invocables</a>,
       <span class="classname"><a href="class.closure.php" class="classname">Closure</a></span>, <span class="type"><a href="language.types.string.php" class="type string">string</a></span>s, o <span class="type"><a href="language.types.array.php" class="type array">array</a></span>s que no tengan
       una estructura válida para ser utilizados como un callback. Un array invocable válido
       contiene 2 entradas: la primera debe ser un objeto
       o un string, y la segunda un string.
      </p>
     </dd>
    
    
     <dt><code class="parameter">callable_name</code></dt>
     <dd>
      <p class="para">
       Recibe el &quot;nombre de la función invocable&quot;, por ejemplo
       <code class="literal">&quot;SomeClass::someMethod&quot;</code>. Tenga en cuenta, sin embargo, que,
       a pesar de la implicación de que <code class="literal">SomeClass::someMethod()</code>
       es un método estático invocable, no es el caso.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.is-callable-returnvalues">
  <h3 class="title">Valores devueltos</h3>
  <p class="para">
   Retorna <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> si <code class="parameter">value</code> puede ser llamado como
   una función, <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> en caso contrario.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.is-callable-examples">
  <h3 class="title">Ejemplos</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Ejemplo #1 Verificación si un string puede ser llamado como una función</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">function </span><span style="color: #0000BB">someFunction</span><span style="color: #007700">() {}<br /><br /></span><span style="color: #0000BB">$functionVariable </span><span style="color: #007700">= </span><span style="color: #DD0000">'someFunction'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">is_callable</span><span style="color: #007700">(</span><span style="color: #0000BB">$functionVariable</span><span style="color: #007700">, </span><span style="color: #0000BB">false</span><span style="color: #007700">, </span><span style="color: #0000BB">$callable_name</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$callable_name</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>El ejemplo anterior mostrará:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">bool(true)
string(12) &quot;someFunction&quot;</pre>
</div>
    </div>
   </div>
   <div class="example" id="example-2">
    <p><strong>Ejemplo #2 Verificación si un array puede ser llamado como una función</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">someClass<br /></span><span style="color: #007700">{<br />    public function </span><span style="color: #0000BB">someMethod</span><span style="color: #007700">() {}<br />}<br /><br /></span><span style="color: #0000BB">$anObject </span><span style="color: #007700">= new </span><span style="color: #0000BB">SomeClass</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$methodVariable </span><span style="color: #007700">= [</span><span style="color: #0000BB">$anObject</span><span style="color: #007700">, </span><span style="color: #DD0000">'someMethod'</span><span style="color: #007700">];<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">is_callable</span><span style="color: #007700">(</span><span style="color: #0000BB">$methodVariable</span><span style="color: #007700">, </span><span style="color: #0000BB">true</span><span style="color: #007700">, </span><span style="color: #0000BB">$callable_name</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$callable_name</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>El ejemplo anterior mostrará:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">bool(true)
string(21) &quot;SomeClass::someMethod&quot;</pre>
</div>
    </div>
   </div>
   <div class="example" id="example-3">
    <p><strong>Ejemplo #3 <span class="function"><strong>is_callable()</strong></span> y los constructores</strong></p>
    <div class="example-contents"><p>
     A pesar de que los constructores son los métodos que se llaman cuando un objeto es creado,
     no son métodos estáticos y
     <span class="function"><strong>is_callable()</strong></span> retornará <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> para ellos. No es
     posible utilizar <span class="function"><strong>is_callable()</strong></span> para verificar si una clase puede
     ser instanciada desde el ámbito actual.
    </p></div>
    <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">Foo<br /></span><span style="color: #007700">{<br />    public function </span><span style="color: #0000BB">__construct</span><span style="color: #007700">() {}<br /><br />    public function </span><span style="color: #0000BB">foo</span><span style="color: #007700">() {}<br />}<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(<br />    </span><span style="color: #0000BB">is_callable</span><span style="color: #007700">([</span><span style="color: #DD0000">'Foo'</span><span style="color: #007700">, </span><span style="color: #DD0000">'__construct'</span><span style="color: #007700">]),<br />    </span><span style="color: #0000BB">is_callable</span><span style="color: #007700">([</span><span style="color: #DD0000">'Foo'</span><span style="color: #007700">, </span><span style="color: #DD0000">'foo'</span><span style="color: #007700">])<br />);<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 /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">is_callable</span><span style="color: #007700">([</span><span style="color: #0000BB">$foo</span><span style="color: #007700">, </span><span style="color: #DD0000">'__construct'</span><span style="color: #007700">]));<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>El ejemplo anterior mostrará:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">bool(false)
bool(false)
bool(true)</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.is-callable-notes">
  <h3 class="title">Notas</h3>
  <ul class="simplelist">
   <li>
    Un objeto es siempre invocable si implementa
    <a href="language.oop5.magic.php#object.invoke" class="link">__invoke()</a>, y que el método es visible
    en el ámbito actual.
   </li>
   <li>Un nombre de clase es invocable si implementa
    <a href="language.oop5.overloading.php#object.callstatic" class="link">__callStatic()</a>
   </li>
   <li>
    Si un objeto implementa <a href="language.oop5.overloading.php#object.call" class="link">__call()</a>, entonces esta función
    retornará <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> para cualquier método en ese objeto, incluso si
    el método no está definido.
   </li>
   <li>
    Esta función puede desencadenar el autoload si es llamada con el nombre
    de una clase.
   </li>
  </ul>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.is-callable-seealso">
  <h3 class="title">Ver también</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.call-user-func.php" class="function" rel="rdfs-seeAlso">call_user_func()</a> - Llama a una funci&oacute;n de retorno proporcionada por el primer argumento</span></li>
    <li><span class="function"><a href="function.function-exists.php" class="function" rel="rdfs-seeAlso">function_exists()</a> - Indica si una funci&oacute;n est&aacute; definida</span></li>
    <li><span class="function"><a href="function.method-exists.php" class="function" rel="rdfs-seeAlso">method_exists()</a> - Verifica si el m&eacute;todo existe en una clase</span></li>
   </ul>
  </p>
 </div>


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