Connecting Tech Pros Worldwide Help | Site Map

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

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 12:16 PM
Peter Albertsson
Guest
 
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



  #2  
Old July 17th, 2005, 12:17 PM
Chung Leong
Guest
 
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...[color=blue]
> 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?[/color]

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


  #3  
Old July 17th, 2005, 12:17 PM
Peter Albertsson
Guest
 
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...[color=blue]
> "Peter Albertsson" <Peter.ANTISPAM.Albertsson@antispOm.comhem.se> wrote in
> message news:N0I0e.133216$dP1.471164@newsc.telia.net...[color=green]
>> 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?[/color]
>
> http://www.php.net/call_user_func/
>
>[/color]


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.