Call a static variable from instance

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

    Call a static variable from instance

    Hi,
    It's possible to call a static variable/method from an instance:

    Object::my_stat ic_var

    I need to do something like this

    $obj = new Object(); // (I have dynamic Object type)

    $obj::my_static _var


    There's any workaround?

    Thanks in advance,
    Luca

  • ZeldorBlat

    #2
    Re: Call a static variable from instance

    On Jun 15, 10:30 am, lux <luca.tavole... @gmail.comwrote :
    Hi,
    It's possible to call a static variable/method from an instance:
    >
    Object::my_stat ic_var
    >
    I need to do something like this
    >
    $obj = new Object(); // (I have dynamic Object type)
    >
    $obj::my_static _var
    >
    There's any workaround?
    >
    Thanks in advance,
    Luca
    Just write a getter/setter for it:

    class Foo {
    public static $bar;

    public function getBar() {
    return self::$bar;
    }

    public function setBar($val) {
    self::$bar = $val;
    }
    }

    Comment

    Working...