is_callable: is method callable : Reflection Class Methods « Class « PHP






is_callable: is method callable

<?php
class Person {
    private $name;    
    private $age;    
    private $id;    

    function __construct( $name, $age ) {
        $this->name = $name;
        $this->age = $age;
    }

    function setId( $id ) {
        $this->id = $id;
    }
    
    function getId(){
        echo "get id method";    
    }
    
    function __clone() {
        $this->id = 0;
    }
}
$p = new Person("A",10);

$method = "getId";     // define a method name

if ( is_callable( array( get_class($p), $method) ) ) {
    print $p->$method();  // invoke the method
}

?>


           
       








Related examples in the same category

1.get_class_methods
2.in_array
3.Call class method dynamically
4.method_exists
5.Get Class method: file name, start line and end line
6.Class method info: is static, is final, is constructor, return references
7.Class method info: is User Defined, is Internal, is Abstract
8.Class method info: is private, is public, is protected