This is a discussion on Syntax for calling a static method on a "variable" class? within the PHP Language forums, part of the PHP Programming Forums category; Hi, I have a classname in a variable, and I whish to call a static method on that class, what'...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
"Peter Albertsson" <Peter.ANTISPAM.Albertsson@antispOm.comhem.se> wrote in
message news:N0I0e.133216$dP1.471164@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/ |
|
|||
|
Great! Thanks!
// Peter "Chung Leong" <chernyshevsky@hotmail.com> wrote in message news:laSdnZ9PcIrjKt7fRVn-2w@comcast.com... > "Peter Albertsson" <Peter.ANTISPAM.Albertsson@antispOm.comhem.se> wrote in > message news:N0I0e.133216$dP1.471164@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/ > > |