函数访问类中所有受保护的变量

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了函数访问类中所有受保护的变量相关的知识,希望对你有一定的参考价值。

  1. /* in the class foo*/
  2. public function get( $var )
  3. {
  4. return $this->$var;
  5. }
  6. /* example var, also in the class*/
  7. protected $bar = 'hello world'
  8.  
  9. /*used like this*/
  10. $foo = new Foo();
  11. print $foo->get('bar');

以上是关于函数访问类中所有受保护的变量的主要内容,如果未能解决你的问题,请参考以下文章