function to access all protected vars in a class


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.