Define class helper class to check the method existance : Reflection Existance « Class « PHP






Define class helper class to check the method existance

<?php
class A {
    function getA( ) {
        return array( "A", "B" );
    }
}

class Helper {
    private $classA;

    function __construct( A $classA ) {
        $this->classA = $classA;
    }

    function __call( $method, $args ) {
        if ( method_exists( $this->classA, $method ) ) {
            return $this->classA->$method( );
        }
    }
}

$tool= new Helper( new A() );
print_r( $tool->getA() );
?>


           
       








Related examples in the same category

1.class_exists: given a class name and check its existance