www.webdeveloper.com
Results 1 to 2 of 2

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

  1. #1
    Join Date
    Apr 2006
    Posts
    219

    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. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,608
    You could just pass the object itself:
    PHP Code:
    $general_form->call_custom_func($transfer'bolge_yukle'); 
    Your custom_func() method would then just need to do:
    PHP Code:
    function call_custom_func($obj$method// might want some type-hinting for $obj
    {
        if(
    method_exists($obj$method) {
            return 
    $obj->$method();
        }
        throw new 
    Exception("Invalid method '$method'");

    That being said, the need to do this might give me pause to take a look at my application design.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles