Access a static variable by $var::$reference

前端 未结 4 628
温柔的废话
温柔的废话 2020-12-10 00:30

I am trying to access a static variable within a class by using a variable class name. I\'m aware that in order to access a function within the class, you

4条回答
  •  情歌与酒
    2020-12-10 01:06

    For calling static members you can use a code like this:

    call_user_func("MyClass::my_static_method");
    // or
    call_user_func(array("MyClass", "my_static_method"));
    

    Unfortunately the only way to get static members from an object seems to be get_class_vars():

    $vars = get_class_vars("MyClass");
    $vars['my_static_attribute'];
    

提交回复
热议问题