is_callable

(PHP 4 >= 4.0.6, PHP 5, PHP 7)

is_callable 锟斤拷锟斤拷锟斤拷锟角凤拷为锟较凤拷锟侥可碉拷锟矫结构

说锟斤拷

is_callable ( callable $name [, bool $syntax_only = false [, string &$callable_name ]] ) : bool

锟斤拷证锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟杰凤拷锟斤拷为锟斤拷锟斤拷锟斤拷锟矫★拷 锟斤拷锟斤拷约锟斤拷锟斤拷锟斤拷锟叫э拷锟斤拷锟斤拷锟斤拷谋锟斤拷锟斤拷锟斤拷锟斤拷锟揭伙拷锟斤拷锟斤拷椋拷锟斤拷锟斤拷锟斤拷锟饺凤拷锟斤拷锟侥讹拷锟斤拷锟皆硷拷锟斤拷锟斤拷锟斤拷锟斤拷

锟斤拷锟斤拷

name

要锟斤拷锟侥回碉拷锟斤拷锟斤拷锟斤拷

syntax_only

锟斤拷锟斤拷锟斤拷锟轿� TRUE锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟街� name 锟斤拷锟斤拷锟角猴拷锟斤拷锟津方凤拷锟斤拷 锟斤拷锟斤拷锟斤拷锟杰撅拷锟斤拷锟街凤拷锟斤拷锟斤拷锟斤拷未锟斤拷锟斤拷锟斤拷锟斤拷锟节回碉拷锟斤拷锟斤拷锟斤拷锟斤拷效锟结构锟斤拷锟斤拷效锟斤拷应锟矫帮拷锟斤拷锟斤拷锟斤拷元锟截o拷锟斤拷一锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷址锟斤拷锟斤拷诙锟斤拷锟皆拷锟斤拷歉锟斤拷址锟斤拷锟�

callable_name

锟斤拷锟斤拷"锟缴碉拷锟矫碉拷锟斤拷锟斤拷"锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟�"someClass::someMethod"锟斤拷 注锟解,锟斤拷锟斤拷 someClass::SomeMethod() 锟侥猴拷锟斤拷锟角可碉拷锟矫的撅拷态锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟接碉拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷摹锟�

锟斤拷锟斤拷值

锟斤拷锟� name 锟缴碉拷锟斤拷锟津返伙拷 TRUE锟斤拷锟斤拷锟津返伙拷 FALSE锟斤拷

锟斤拷锟斤拷

Example #1 is_callable() 锟斤拷锟斤拷

<?php
//  How to check a variable to see if it can be called
//  as a function.

//
//  Simple variable containing a function
//

function someFunction() 
{
}

$functionVariable 'someFunction';

var_dump(is_callable($functionVariablefalse$callable_name));  // bool(true)

echo $callable_name"\n";  // someFunction

//
//  Array containing a method
//

class someClass {

  function 
someMethod() 
  {
  }

}

$anObject = new someClass();

$methodVariable = array($anObject'someMethod');

var_dump(is_callable($methodVariabletrue$callable_name));  //  bool(true)

echo $callable_name"\n";  //  someClass::someMethod

?>

锟轿硷拷

  • function_exists() - 锟斤拷锟斤拷锟斤拷锟斤拷暮锟斤拷锟斤拷丫锟斤拷锟斤拷锟斤拷锟酵凤拷锟斤拷 TRUE
  • method_exists() - 锟斤拷锟斤拷锟侥凤拷锟斤拷锟角凤拷锟斤拷锟�