5

"Fatal error: Class name must be a valid object or a string in C:\xampp\htdocs\uc\includes\common.inc on line 7506"

The error above showed up unexpectedly. I was adding a "Long text" field to a content-type, but when I expected to be brought to a saved field configuration page, I instead got a Fatal error on every page.

I had a look at includes\common.inc:

/**
 * Get the entity controller class for an entity type.
 */
function entity_get_controller($entity_type) {
  $controllers = &drupal_static(__FUNCTION__, array());
  if (!isset($controllers[$entity_type])) {
    $type_info = entity_get_info($entity_type);
    $class = $type_info['controller class'];
    $controllers[$entity_type] = new $class($entity_type); // Line 7506
  }
  return $controllers[$entity_type];
}

However, I just don't understand Drupal at a low enough level to understand the relationships between these variables and functions.

I also searched Drupal for people with a similar problem:

(1) I found one user who claims that I have to install the submodule "Relation Endpoints Field", but searching Drupal, there doesn't seem to be such a module.

(2) Another user suggested clearing the cache manually:

DELETE FROM cache;
DELETE FROM cache_filter;
DELETE FROM cache_menu;
DELETE FROM cache_page;
DELETE FROM watchdog;

(via WordPress API, misleading name, I know.)

Clearing those tables from the cache did not help.

(3) And another user suggested disabling old modules, specifically the "Old search facets" module. Because I can't find a module specifically pertaining to old search facets, I went into MySQL system table, and marked the Search module's line with a 0 status, indicating to stop loading the module altogether.

On that same link as (3), one user suggested enabling the Database Search Module, so I dropped all the tables, imported the latest stable .sql, and installed the module, but after recreating the problem (trying to add a field to a content-type), that as well concluded fruitless.

Still, the problem remains

The Fatal error shows up on every page, making the site completely non-functional. Any help or direction would be immensely appreciated. Thank you for looking.

migrated from stackoverflow.com Nov 17 '11 at 16:31

This question came from our site for professional and enthusiast programmers.

  • better to not put solution into the question. you can post answers for your question below as well – milkovsky Nov 4 '13 at 12:18
8

The error means that Drupal can't find the entity type information for a entity that it tries to load.

Add var_dump($entity_type); in there and reload the page. The last one that it's going to print (if there are multiple) is the culprit. What you need to do then depends on the entity type. It could for example be that you disabled a module which is still being called.

  • I'm going to try this out - thank you for the direction. I'll come back to upvote if it works. :) – Morgan Delaney Nov 17 '11 at 0:53
  • So your first line was right, it was definitely a missing entity information issue. I posted exactly the relevant steps to helping me find where it was coming from. Thank you. – Morgan Delaney Nov 17 '11 at 9:17
1

This issue has been raised and closed (without repair) a huge number of times (more than 50 that I can see). It is, admittedly, a tough one to find. I have entered the issue. I have tracked down the actual cause, but the intricacies of the cache are a bit beyond me.

Clearing the cache could help here. Sadly, you can't always get there, largely because drush cc will also blow up when this error is occurring. So will anything having to do with accessing a user (in my case). . Requiring a user to clear the cache every time this occurs is improper by its nature - you can't have a user do a workaround as a normal course of business.

This is the tip of the iceberg on this problem. (the PHP Fatal error: Class name must be a valid object or a string in /includes/common.inc on line 7522).

[[[[in 7.28, at line 7855, 6 = ]]]] $class = $type_info['controller class']; $controllers[$entity_type] = new $class($entity_type);

The symptom appears because the search for the element ['controller class'] is presumed to be successful. It is not, and no secondary message (such as in a try / catch or an actual test here) is generated.

The issue stems from, for whatever reason, not being able to obtain a $class value from the $type_info array by executing module_invoke_all('entity_info'). Certainly a call time pass by reference could do it, but that would normally be caught. The actual problem is in /includes/common.inc at 7644.

      if (empty($entity_info)) {
        if ($cache = cache_get("entity_info:$langcode")) {
          $entity_info = $cache->data;
        }
        else {
          $entity_info = module_invoke_all('entity_info');
          // Merge in default values.
          foreach ($entity_info as $name => $data) {
            $entity_info[$name] += array(
              'fieldable' => FALSE,
              'controller class' => 'DrupalDefaultEntityController',
              'static cache' => TRUE,
              'field cache' => TRUE,
              'load hook' => $name . '_load',
              'bundles' => array(),
              'view modes' => array(),
              'entity keys' => array(),
              'translation' => array(),
            );
            $entity_info[$name]['entity keys'] += array(
              'revision' => '',
              'bundle' => '',
            );
            foreach ($entity_info[$name]['view modes'] as $view_mode => $view_mode_info) {
              $entity_info[$name]['view modes'][$view_mode] += array(
                'custom settings' => FALSE,
              );
            }
            // If no bundle key is provided, assume a single bundle, named after
            // the entity type.
            if (empty($entity_info[$name]['entity keys']['bundle']) && empty($entity_info[$name]['bundles'])) {
              $entity_info[$name]['bundles'] = array($name => array('label' => $entity_info[$name]['label']));
            }
            // Prepare entity schema fields SQL info for
            // DrupalEntityControllerInterface::buildQuery().
            if (isset($entity_info[$name]['base table'])) {
              $entity_info[$name]['schema_fields_sql']['base table'] = drupal_schema_fields_sql($entity_info[$name]['base table']);
              if (isset($entity_info[$name]['revision table'])) {
                $entity_info[$name]['schema_fields_sql']['revision table'] = drupal_schema_fields_sql($entity_info[$name]['revision table']);
              }
            }
          }
          // Let other modules alter the entity info.
          drupal_alter('entity_info', $entity_info);
          cache_set("entity_info:$langcode", $entity_info);
        }
      }

Notice that if the condition is true in the if at

if ($cache = cache_get("entity_info:$langcode")) {
  $entity_info = $cache->data;
}

then the module_invoke_all('entity_info') is never executed. It just happens that the condition is always met after some other processing is done to create the cache. That means that there is no way to get the entity_info set up --- in my case there was no way to obtain the 'user' entity info, causing the original error above. I made the 'else' one level higher (took out the 'else {}') for testing, and everything worked as it should to clear the error.

I believe that the real bug is that the checking of cache is less than adequate, and that a check on the existence of the entity_info about the specific entity being searched for is needed. In fact, it may be justifiable to also search for the element ['controller class'] for that entity in the entity_info stored in cache. D

0

I felt stupid after spending a day to find two typos but if this helps anyone..

I have a custom module that creates new fieldable entity type with bundles: I used word 'entity' as a last word in my module's name and later used search and replace to change: module_name_entity to module_name.

Due to this or some previous hook_entity_property_info() and hook_entity_info() were now called: module_name_property_info() and module_name_info() without the hooks 'entity' part in the function name.

That caused common.inc not to find the entity info and produced this error for me.

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.