in_array : Reflection Class Methods « Class « PHP






in_array


<?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 ( in_array( $method, get_class_methods( $p ) ) ) {
    print $p->$method();  // invoke the method
}

?>

           
       








Related examples in the same category

1.get_class_methods
2.is_callable: is method callable
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