Dyanmically Call Static Member

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ryanmhuc@yahoo.com

    #1

    Dyanmically Call Static Member

    Is it possible to dyanmically call a classes static member or property?
    So something like

    class test1 {
    static $staticVar = "Help";
    }

    $className = "test1";
    echo $className::$st aticVar;

    This produces an error. Does anyone know if its possible? Thanks

  • reandeau

    #2
    Re: Dyanmically Call Static Member

    This is a known bug / limitation in PHP. See



    Jon Tjemsland

    Comment

    • reandeau

      #3
      Re: Dyanmically Call Static Member

      Found a work around to dyanmically calling a classes static member.
      Try the following with eval:

      $className = "test1";
      eval('$instance = ' . $className . '::$staticVar;' );
      echo "test: $instance";


      Let me know how it goes.

      Jon Tjemsland

      Comment

      Working...