Advertisement
Guest User

Untitled

a guest
Sep 25th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. class test
  2. {
  3. private $a = 0;
  4. protected $b = 0;
  5. public $c = 0;
  6.  
  7. public function echoprop()
  8. {
  9. foreach($this as $key => $val)
  10. {
  11. echo "$".$key." = ".$val.";n";
  12. }
  13. }
  14. }
  15. $var = new test;
  16. $var->echoprop();
  17.  
  18. <?php
  19. class test
  20. {
  21. private $a = 0;
  22. protected $b = 0;
  23. public $c = 0;
  24.  
  25. public function echoprop()
  26. {
  27. $reflector = new ReflectionClass(get_class($this));
  28.  
  29. foreach($this as $key => $val)
  30. {
  31. $prop = $reflector->getProperty($key);
  32. if( $prop->isPrivate() ) {
  33. echo 'Private';
  34. } else if( $prop->isProtected() ) {
  35. echo 'Protected';
  36. } else if( $prop->isPublic() ) {
  37. echo 'Public';
  38. }
  39.  
  40. echo "$".$key." = ".$val.";n";
  41. }
  42. }
  43. }
  44. $var = new test;
  45. $var->echoprop();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement