Switch to full style
:read: Start PHP with us. Includes topics to help you in php
Post a reply

invoke class method dynamically in php

Mon Oct 27, 2008 12:13 am

Code:

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

    function
setA( $country, $district ) {
        return
"$country, $district\n";
    }

}

class
Helper {
    
private $classA;

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

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

$tool= new Helper( new A() );
print_r( $tool->setA( 'UK', 'BN' ) );
?>




Post a reply
  Related Posts  to : invoke class method dynamically in php
 General call (Invoke) to method     -  
 Define class helper class to check the method existance     -  
 define a Class with a Method     -  
 toString method in class php     -  
 Calling Functions Dynamically     -  
 Add new row dynamically to table using JQuery     -  
 Dynamically Create Image     -  
 java abstract class,concrete class and interface     -  
 Uplading Files Dynamically Using SSIS     -  
 Add and Remove CSS classes to html tag dynamically     -  

Topic Tags

PHP OOP