Access Private Properties With For Each Loop

<?
    class Person {
            public $FirstName = "B";
            public $MiddleName = "T";
            public $LastName = "M";
            private $Password = "asdfasdf";
            public $Age = 29;
            public $HomeTown = "LA";
            public $FavouriteColor = "Purple";            public function outputVars( ) {
                    foreach($this as $var => $value) {
                            echo "$var is $value\n";
                    }
            }
    }    $bill = new Person( );
    $bill->outputVars( );
?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.