Welcome to Discuss Everything Forums...

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.


 

Tags for this Thread

+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    I've used it on the occasion when I needed to call one of several functions based on user input. It saves me the effort of doing a long, tedious if-statement. For example:

    function example($param) {
    $result = call_user_func($param);
    }

    instead of:

    func other_example($param) {
    if($param == 'some_value') {
    $result = some_function();
    }
    elseif($param == 'some_other_value') {
    $result = some_other_function();
    }
    ...
    }

  2. #2
    Peter's Avatar
    Senior Member

    Status
    Offline
    Join Date
    May 2009
    Posts
    869
    Downloads
    0
    Uploads
    0

    What is call_user_func used for in PHP?

    We can directly call a function by its name, e.g.

    my_function($arg1);

    So why do we have an extra call_user_func function used to call other functions?

    Thank you very much for your help.

  3. #3
    I've used it on the occasion when I needed to call one of several functions based on user input. It saves me the effort of doing a long, tedious if-statement. For example:

    function example($param) {
    $result = call_user_func($param);
    }

    instead of:

    func other_example($param) {
    if($param == 'some_value') {
    $result = some_function();
    }
    elseif($param == 'some_other_value') {
    $result = some_other_function();
    }
    ...
    }

  4. #4
    I've used it on the occasion when I needed to call one of several functions based on user input. It saves me the effort of doing a long, tedious if-statement. For example:

    function example($param) {
    $result = call_user_func($param);
    }

    instead of:

    func other_example($param) {
    if($param == 'some_value') {
    $result = some_function();
    }
    elseif($param == 'some_other_value') {
    $result = some_other_function();
    }
    ...
    }

  5. #5
    I've used it on the occasion when I needed to call one of several functions based on user input. It saves me the effort of doing a long, tedious if-statement. For example:

    function example($param) {
    $result = call_user_func($param);
    }

    instead of:

    func other_example($param) {
    if($param == 'some_value') {
    $result = some_function();
    }
    elseif($param == 'some_other_value') {
    $result = some_other_function();
    }
    ...
    }

  6. #6
    I've used it on the occasion when I needed to call one of several functions based on user input. It saves me the effort of doing a long, tedious if-statement. For example:

    function example($param) {
    $result = call_user_func($param);
    }

    instead of:

    func other_example($param) {
    if($param == 'some_value') {
    $result = some_function();
    }
    elseif($param == 'some_other_value') {
    $result = some_other_function();
    }
    ...
    }

  7. #7
    I've used it on the occasion when I needed to call one of several functions based on user input. It saves me the effort of doing a long, tedious if-statement. For example:

    function example($param) {
    $result = call_user_func($param);
    }

    instead of:

    func other_example($param) {
    if($param == 'some_value') {
    $result = some_function();
    }
    elseif($param == 'some_other_value') {
    $result = some_other_function();
    }
    ...
    }

 

 

Quick Reply Quick Reply

Click here to log in


What is the sum of 36 and 12

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 0
    Last Post: 03-09-2011, 04:43 AM
  2. Replies: 0
    Last Post: 09-25-2010, 01:37 PM
  3. Replies: 0
    Last Post: 02-02-2010, 06:40 AM
  4. Replies: 0
    Last Post: 09-10-2009, 08:32 AM
  5. Replies: 1
    Last Post: 05-19-2009, 10:46 AM

Bookmarks

Posting Permissions

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