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

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'...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-25-2005
Peter Albertsson
 
Posts: n/a
Default Syntax for calling a static method on a "variable" class?

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


Reply With Quote
  #2 (permalink)  
Old 03-25-2005
Chung Leong
 
Posts: n/a
Default Re: Syntax for calling a static method on a "variable" class?

"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/


Reply With Quote
  #3 (permalink)  
Old 03-25-2005
Peter Albertsson
 
Posts: n/a
Default Re: Syntax for calling a static method on a "variable" class?

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/
>
>



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:41 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0