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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Albertsson

    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::ba r() // This is an error... "parse error, unexpected
    T_PAAMAYIM_NEKU DOTAYIM"

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

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

    Regards,

    Peter Albertsson


  • Chung Leong

    #2
    Re: Syntax for calling a static method on a &quot;variable& quot; class?

    "Peter Albertsson" <Peter.ANTISPAM .Albertsson@ant ispOm.comhem.se > wrote in
    message news:N0I0e.1332 16$dP1.471164@n ewsc.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]

    Call the callback given by the first parameter



    Comment

    • Peter Albertsson

      #3
      Re: Syntax for calling a static method on a &quot;variable& quot; class?

      Great! Thanks!

      // Peter

      "Chung Leong" <chernyshevsky@ hotmail.com> wrote in message
      news:laSdnZ9PcI rjKt7fRVn-2w@comcast.com. ..[color=blue]
      > "Peter Albertsson" <Peter.ANTISPAM .Albertsson@ant ispOm.comhem.se > wrote in
      > message news:N0I0e.1332 16$dP1.471164@n ewsc.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]


      Comment

      Working...