Inspect object in PHP

To display the contents of an object in ruby is really simple.
All you do is store the object in a variable, then pass the variable as an argument to the Kernel method p(), which in turn writes obj.inspect to the standard output.

For example:

Outputs: #<Person:0x1a58d8 @age=68, @name="Robert DeNiro">

I was recently doing something in WordPress where it would have been really useful to see the contents of an object I was fetching.

Here’s how I solved the problem:

This does what it should, but I still think the ruby way is less cumbersome though …

N.B. Also useful was PHP’s count() function, which returns the length of an array.
This is documented here:

Edit: since getting a bit more into PHP, I have discovered the nifty function print_r(), which outputs human-readable information about a variable. You can read more about this here:

I'm on Twitter: