Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class test
- {
- private $a = 0;
- protected $b = 0;
- public $c = 0;
- public function echoprop()
- {
- foreach($this as $key => $val)
- {
- echo "$".$key." = ".$val.";n";
- }
- }
- }
- $var = new test;
- $var->echoprop();
- <?php
- class test
- {
- private $a = 0;
- protected $b = 0;
- public $c = 0;
- public function echoprop()
- {
- $reflector = new ReflectionClass(get_class($this));
- foreach($this as $key => $val)
- {
- $prop = $reflector->getProperty($key);
- if( $prop->isPrivate() ) {
- echo 'Private';
- } else if( $prop->isProtected() ) {
- echo 'Protected';
- } else if( $prop->isPublic() ) {
- echo 'Public';
- }
- echo "$".$key." = ".$val.";n";
- }
- }
- }
- $var = new test;
- $var->echoprop();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement