How to see inside a PHP object
I am working with a 3-rd party library and it makes some random call like this:
$consumer = getConsumer();
And I don't know what are the values inside the $consumer variable I tried to do something like this:
echo '<p>consumer: '.$consumer.'</p>';
but that just crashed the page :) What is the real way for me to see what objects and values are in this $consumer 开发者_开发知识库object? And whats the best way to extract them?
Thanks!
Try var_dump($consumer);
or print_r($consumer);
.
If it's an object, you access its parameters like so:
$consumer->parameter
In case you do somehow manage to get access to the object (class) itself Reflection API is an invaluable resource when it comes to dissecting objects in PHP > 5.
You could try var_dump:
$consumer = getConsumer();
var_dump($consumer); // no echo required
I'm pretty rusty on my PHP, but you might want to have a look at var_dump as well:
$consumer = getConsumer();
var_dump($consumer);
More info here: http://www.php.net/manual/en/function.var-dump.php
精彩评论