Mega Code Archive

 
Categories / Php / Class
 

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() ); ?>