Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Apr 2006
    Posts
    128
    Thanks
    6
    Thanked 0 Times in 0 Posts

    How to call a class function from another class using the parameters given

    Hi,

    I have a PHP file calling the following function of the following class

    PHP Code:
    <?
                $transfer 
    = new transfer();
                
    $transfer->bolge_yukle();
                
    ?>
    Is it possible to send the class transfer() and function bolge_yukle() to another class as a parameter to be called from there?

    For example:

    I have function of general.php which includes many general form functions but sometimes I would like to call the custom class and functions. I want to a add a function to General.php to call the custom class and functions. e.g:
    PHP Code:
    $custom_func1 = new general_form();
    $general_form->call_custom_func('transfer','bolge_yukle'); 
    I hope I could explain the situation.

    Kindest regards
    telmessos.

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Like this?
    PHP Code:
    class general_form
    {

        public function 
    call_custom_func$class$func )
        {
            
    $class = new $class;
            return 
    $class->$func();
        }


    Of course there are more complex methods like reflection:
    PHP Code:
    class general_form
    {

        public function 
    call_custom_func$class$func )
        {
            
    $class  = new ReflectionClass$class );
            
    $object $class->newInstance();
            return 
    $class->getMethod$func )->invoke$object );
        }




  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •