By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,934 Members | 1,538 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,934 IT Pros & Developers. It's quick & easy.

Syntax for calling a static method on a "variable" class?

P: n/a
Hi,

I have a classname in a variable, and I whish to call a static method on
that class, what's the syntax for that?

I'm using PHP5.

Eg.

<?php
class Foo {
public static function bar() {
echo "Foo bar";
}
}

$class_name = 'Foo';

$foo = new $class_name(); // I can do this.

$class_name::bar() // This is an error... "parse error, unexpected
T_PAAMAYIM_NEKUDOTAYIM"

Foo::bar() // This is how it's normally done..
?>

So what I want to do is $class_name::bar(), is it possible and what is the
syntax?

Regards,

Peter Albertsson
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Peter Albertsson" <Pe***********************@antispOm.comhem.se> wrote in
message news:N0*********************@newsc.telia.net...
Hi,

I have a classname in a variable, and I whish to call a static method on
that class, what's the syntax for that?


http://www.php.net/call_user_func/
Jul 17 '05 #2

P: n/a
Great! Thanks!

// Peter

"Chung Leong" <ch***********@hotmail.com> wrote in message
news:la********************@comcast.com...
"Peter Albertsson" <Pe***********************@antispOm.comhem.se> wrote in
message news:N0*********************@newsc.telia.net...
Hi,

I have a classname in a variable, and I whish to call a static method on
that class, what's the syntax for that?


http://www.php.net/call_user_func/

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.