Posted By

Zwendel on 10/28/09


Tagged

class variables function variable access vars protected var


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

kellyrmartin
Zwendel


function to access all protected vars in a class


 / Published in: PHP
 

  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');

Report this snippet  

You need to login to post a comment.