0

The data I need are reported by Devel to be objects of stdClass.
What is that class? Is it a $node, $term or $page? Without guessing, how do I determine what that object is, in order to extract data?

1
3

So, you have a variable. Lets say $object, and you call dsm, dpm, dvm or one of devel's other debugging functions to inspect it:

$node = node_load(1);
dpm($node);

Devel gives you something back like this:

object(stdClass)[79]
  public 'nid' => string '1' (length=1)
  public 'type' => string 'profile' (length=7)
  public 'language' => string '' (length=0)
  ...

The stdClass part just means that its a generic empty class, not any particular type of object. So, you can access all of its properties using standard object notation, but there are no object specific functions that you can call from the object.

So, for example, you can call:

$nid = $node->nid;
$type = $node->type;

But you can't do anything like this:

$result = $node->some_special_node_function();

Because there are no special node functions.

In Drupal, most things that get retuned as objects are just generic objects without any type special attributes or functions.

1
  • Just to add to that - devel is not going to explicitly tell you what type of object you are inspecting, but generally speaking you would probably know what object you have passed to devel, or you would be able to work out what object it is by looking at some of the properties that devel reports that it has. For example, if it has $object->nid, then its probably a node, since it has a node id (nid). – Tom Kirkpatrick May 13 '11 at 22:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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