Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
functions as variables in a function in PHP
Old 04-07-2005, 01:49 PM functions as variables in a function in PHP
Recrehal's Avatar
Experienced Talker

Posts: 39
Location: Aachen, Germany
Trades: 0
I'd like to create a function that gets the name of another function as a parameter so that this function may be called later.

It might look a bit like this, but I'm openminded for propper code
PHP Code:
function my_function(call_me_function)
{
call_me_function();
}
 
myfunction(another_function); 
I'm not sure if that is possible but it would safe me the time of writing an endless case block with all the little functions that might be called and browsing through a list of additional functions that might be edited later. If I could just say the name of the function I'd like to call that would be one simple line

Oh and I think my host provides me with some PHP4 version, but if you know a way to do it in PHP5 I'd also be interested
Recrehal is offline
Reply With Quote
View Public Profile Visit Recrehal's homepage!
 
 
Register now for full access!
Old 04-07-2005, 02:36 PM
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
You can use the contents of a variable as a function. For example:

PHP Code:
$func 'print_r';

$func(array(1234));
// is the same as
print_r(array(1234)); 
So you can pass the name of a function as a paramter, and simply use the variable as if it were the function name.

PHP Code:
function my_function($call_me)
{
    
$call_me();
}

my_function('str_replace'); 
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to functions as variables in a function in PHP
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11263 seconds with 12 queries