As this page shows, you can simply iterate over an object:
<?php class person { public $FirstName = "Bill"; public $MiddleName = "Terence"; public $LastName = "Murphy"; private $Password = "Poppy"; public $Age = 29; public $HomeTown = "Edinburgh"; public $FavouriteColour = "Purple"; } $bill = new person(); foreach($bill as $var => $value) { echo "$var is $value\n"; } ?>
Please note that the $ Password variable is not visible anywhere, because it is allocated by Private, and we are trying to access it from the global scope.
If you want to create your own var dump, you can do it like this:
function dumpObj( $obj ) { foreach( $obj as $k=>$v ) { echo $k . ' : ' . $v ."\n"; } } dumpObj( new WhateverClass() );
The reason this happens is that when you access an object outside of you, you have access to its public member variables.
source share