Connecting Tech Pros Worldwide Help | Site Map

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

  #1  
Old July 17th, 2005, 01:16 PM
Peter Albertsson
Guest
 
Posts: 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


  #2  
Old July 17th, 2005, 01:17 PM
Chung Leong
Guest
 
Posts: n/a

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, 01:17 PM
Peter Albertsson
Guest
 
Posts: n/a

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]


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pointers and polymorphism explained [preview, PDF, part of my attempted "Correct C++ Tutorial"] Alf P. Steinbach answers 53 November 28th, 2005 11:55 AM