Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I'm sure this question applies to other complex object types, but EntityDrupalWrapper is the one I'm currently working with. This is the type of object returned by entity_metadata_wrapper() (and probably others).

When using code like the following:

$order_wrapper = entity_metadata_wrapper('commerce_order', $order_object);
dpm($order_wrapper);

the output from Devel is none too helpful:

screenshot

It doesn't show what you'd expect to see for a call to dpm() with, for example, a stdClass object.

A similar call to dvm() does print the object, but in a manner I'm not familiar with, and it's not very readable.

I've tried debug() and it produces a PHP user notice that looks something like this:

screenshot 2

Incidentally the HTML output contained in that warning is the same output that dvm() prints to the screen.

How can I inspect these types of objects (preferably with Krumo), so I can see what properties are available? Or am I stuck using dvm()?

share|improve this question
    
try debug() introduced in Drupal 7 –  Shuaib Nawaz Jun 7 '12 at 20:06
    
Thanks @ShuaibNawaz, even less success with that one though I'm afraid (I've updated the question) –  Clive Jun 7 '12 at 20:10
1  
Yep, that's exactly one of the problems with the wrapper classes. dpm()/krumo only sees public properties. Everything in the wrapper classes is protected and access through magic __get() and __set() methods. –  Berdir Jun 7 '12 at 20:12
    
@Berdir I was afraid of that; I hadn't looked but it did smell a lot like __get() and __set() were involved. Out of interest do you have any preferred way of finding out what class properties are available for what wrapper? Or is it just a matter of 'knowing' based on experience? –  Clive Jun 7 '12 at 20:17
    
@Berdir I don't think you'll get notified of this, you can use dpm($wrapper->getPropertyInfo());, it really helps things –  Clive Sep 13 '12 at 13:17

5 Answers 5

up vote 17 down vote accepted

Use dpm($wrapper->getPropertyInfo());

It's in the docs.

share|improve this answer

I had been playing with EntityDrupalWrapper objects. debug() usually returns the output that may have prepared by __toString()

I iterated EntityDrupalWrapper object using foreach and it helped to list down the name of properties.

foreach($order_wrapper as $name => $obj){
  debug($name);
  debug(get_class($obj)); //EntityValueWrapper
}

Here $obj is an object of type EntityValueWrapper

$obj can be read by $obj->value() and can be write by $obj->set('value');

EDIT:

If you have created your wrapper without passing second param
i.e. entity_metadata_wrapper('commerce_order');
then set and value methods will throw exception as they are not implemented.

share|improve this answer
    
Thanks that's a good start, I'll leave the question open for a bit to see if anyone's got any other ideas –  Clive Jun 7 '12 at 20:40

The Inspect module provides a nice structural view of the data you want to debug.

Get instructive and well formatted variable dumps, deep stack traces, and execution time profiles - to database log (Reports / Recent log messages), to file or to screen.

share|improve this answer

I wound up writing my own little widget to unroll the wrapper:

function _wrapper_debug($w) {
  $values = array();
  foreach ($w->getPropertyInfo() as $key => $val) {
    $values[$key] = $w->$key->value();
  }
  return $values;
}

dpm(_wrapper_debug($some_object_wrapper));

Hope someone finds it useful.

share|improve this answer

If you want to inspect the original object that is "powering" the wrapper, try:

dpm($wrapper->raw())

This works well for me.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.