PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
kendall
Forum Regular
Posts: 852 Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:
Post
by kendall » Fri Sep 12, 2008 11:51 am
Hi,
How can I execute the method of a class that is passed via a variable?
e.g.
Code: Select all
// class
class M {
function send(){
}
}
$class_method = 'send'; // the method of class M
$test = new M();
thus the accessing of it will be
or
ahowell
Forum Newbie
Posts: 17 Joined: Mon Sep 01, 2008 9:18 pm
Post
by ahowell » Fri Sep 12, 2008 12:13 pm
Code: Select all
class foo
{
public function bar()
{
echo 'bar';
}
}
$foo = new foo();
$method = 'bar';
$foo->$method();