NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page PHP: How to pass a function as parameter?

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 03-02-2008, 02:48 AM THREAD STARTER               #1 (permalink)
NamePros Member
Join Date: Mar 2008
Posts: 46
evdoxos is an unknown quantity at this point
 



PHP: How to pass a function as an argument?


In PHP, what is the way to pass a function as an argument in an other function?
Last edited by evdoxos; 03-02-2008 at 03:15 AM.
evdoxos is offline  
Old 03-02-2008, 06:05 AM   #2 (permalink)
Senior Member
 
Dave's Avatar
Join Date: Jun 2007
Location: NamePros.com
Posts: 1,400
Dave has much to be proud ofDave has much to be proud ofDave has much to be proud ofDave has much to be proud ofDave has much to be proud ofDave has much to be proud ofDave has much to be proud ofDave has much to be proud ofDave has much to be proud of
 


Cancer
Well if you want to call a function you can use the call_user_func function. If you need to pass the function name as parameter you would do this...

Code:
<?php
function myFunction($callbackFunc)
{
    // Do whatever you got to here...

   // and then..
    call_user_func($callbackFunc);
}
?>
Hope this helps.
Dave is offline  
Old 03-02-2008, 02:00 PM THREAD STARTER               #3 (permalink)
NamePros Member
Join Date: Mar 2008
Posts: 46
evdoxos is an unknown quantity at this point
 



Thanks a lot. But my problem is more complicated:

<?php

class a
????: NamePros.com http://www.namepros.com/programming/439274-php-how-to-pass-function-parameter.html
{
public function f()
{
echo "af";
}
}

function func($g)
{
class b extends a
{
public function f()
{
echo "bf";
// I want to call function g from here
}
}
$b1 = new b();
$b1->f();
}

function g()
{
echo "g";
}

// From here I want to call function func with argument the funtion g

?>
evdoxos is offline  
Old 03-02-2008, 02:39 PM   #4 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
why have you got a class within a function (class b is within the func function)?

This looks like very bad code design.
__________________
Manage your portfolio using my new Domain Portfolio Management script.
Securing Your Domain Name From Theft
Peter is offline  
Old 03-02-2008, 03:21 PM THREAD STARTER               #5 (permalink)
NamePros Member
Join Date: Mar 2008
Posts: 46
evdoxos is an unknown quantity at this point
 



I need to call the following lines of code -the body of function func- from many locations in my application. So I use a function. Is it a bad idea?
(class a -not b- has a lot lines of code)
Also functions like g are more than 50!

class b extends a
{
public function f()
{
echo "bf";
// I want to call function g from here
}
}
$b1 = new b();
$b1->f();
Last edited by evdoxos; 03-02-2008 at 03:26 PM.
evdoxos is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 08:09 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger