Hi,
I am trying entity module with Profile 2 module and I am getting followin warning:

Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of /www/site.com/beta2/includes/entity.inc).
Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->cacheGet() (line 354 of /www/site.com/beta2/includes/entity.inc).

As I do not know PHP I cannot tell if this is problem in entity module design or in setting of PHP on web server. Fact is I still think that it is problem because of it Profile 2 Page module does not work properly.

CommentFileSizeAuthor
#14 fix_entity.patch1.27 KBstephenrobinson

Comments

valkajemir’s picture

Title: Problem » Problem with array_flip()
fago’s picture

Status: Active » Postponed (maintainer needs more info)

Please report the module versions you have used + when exactly the error occurs.

drbeaker’s picture

Version: 7.x-1.x-dev » 7.x-1.0-beta6

I'm getting the same error.

I can reproduce it by: following the sequence People|User|Edit.

Entity API Version 7.x-1.0-beta6
Drupal 7.0

HTH

Blooniverse’s picture

No good news: I even get this error when using 'Entity API 7.x-1.x-dev (2011-Jan-12)' -- straight after logging in as a user! The error code does not disappear after refreshing '/user', but it occurs only there [on '/user'], no matter which user (admin as well!). Even the line numbers are still the same:

Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (Zeile 178 von /var/www/drupal7/includes/entity.inc).
Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->cacheGet() (Zeile 354 von /var/www/drupal7/includes/entity.inc).

My system:

  • 'Drupal core 7 (2011-Jan-05)'
  • 'Entity API 7.x-1.x-dev (2011-Jan-12)'
  • About 70 additional modules, amongst them is 'Rules 7.x-2.x-dev (2011-Jan-13)'

php.net is telling me:

array array_flip ( array $trans )
array_flip() returns an array in flip order, i.e. keys from trans become values and values from trans become keys.
Note that the values of trans need to be valid keys, i.e. they need to be either integer or string. A warning will be emitted if a value has the wrong type, and the key/value pair in question will not be flipped.
If a value has several occurrences, the latest key will be used as its values, and all others will be lost.

Good news, or not?: According to http://ch.php.net/manual/en/function.array-flip.php, this problem should be easy to solve!

Blooniverse’s picture

Version: 7.x-1.0-beta6 » 7.x-1.x-dev

... the question is: from where exactly comes $trans ($foo), since obviously '/includes/entity.inc' seems to have a problem with it.

fago’s picture

This error always appears if entity_load() is called in a wrong way, e.g. entity_load('type', 4). It has to be entity_load('type', array(4));

Blooniverse’s picture

Devel output (my search keyword is 'entity'):

Arrays:

content (Array, 4 elements) 
 system_main (Array, 15 elements) 
  [...]
  #entity_type (String, 4 characters ) user
  [...]

Queries of 'DrupalDefaultEntityController::load()':

SELECT base.uid AS uid, base.name AS name, base.pass AS pass, base.mail AS mail, base.theme AS theme, base.signature AS signature, base.signature_format AS signature_format, base.created AS created, base.access AS access, base.login AS login, base.status AS status, base.timezone AS timezone, base.language AS language, base.picture AS picture, base.init AS init, base.data AS data FROM sec_users base WHERE (base.uid IN (:db_condition_placeholder_0)) 
SELECT base.fid AS fid, base.uid AS uid, base.filename AS filename, base.uri AS uri, base.filemime AS filemime, base.filesize AS filesize, base.status AS status, base.timestamp AS timestamp FROM sec_file_managed base WHERE (base.fid IN (:db_condition_placeholder_0)) 

'DrupalDefaultEntityController->cacheGet()' shows no Devel query output.

((And when I check XHProf (Profiling), there is no function etc with the keyword 'entity', which seems problematic concerning the consumption of time. ))

Blooniverse’s picture

Okay, @fago (#6), we have the choice (output from Notepad++ on Win):

Search "entity_load" (41 hits in 9 files)

entity.api.php (2 hits)
 Line 44:  *     API functions like entity_load(), but the numeric id as specified by the
 Line 60:  *     controller during entity_load(). Defaults to 'default_' . $entity_type.

entity.features.inc (3 hits)
 Line 62:     foreach (entity_load($this->type, FALSE) as $name => $entity) {
 Line 73:     foreach (entity_load($this->type, $data) as $name => $entity) {
 Line 105:     foreach (entity_load($this->type, $data) as $name => $entity) {

entity.module (8 hits)
 Line 289:  *   entity_load().
 Line 445:  * providing defaults in code is activated. This allows module and entity_load()
 Line 471:  * Actually rebuild the defaults, triggered by entity_load().
Line 501:     $overridden_entities = entity_load($entity_type, array_keys($entities), array($keys['status'] => ENTITY_OVERRIDDEN));
 Line 505:     $existing_entities = entity_load($entity_type, array_keys($entities), array($keys['status'] => ENTITY_CUSTOM));
 Line 517:       if ($entity->original = entity_load_unchanged($entity_type, $name)) {
 Line 558:       $entities = entity_load($entity_type, array_keys($result[$entity_type]));
 Line 569:       foreach (entity_load($entity_type, array_keys($result[$entity_type])) as $name => $entity) {

entity.test (14 hits)
 Line 110:     $types = entity_load('entity_test_type', array('test', 'test2'));
 Line 115:     $types = entity_load('entity_test_type', FALSE, array('label' => 'label'));
 Line 122:     $types = entity_load('entity_test_type', FALSE, array('label' => 'modified'));
 Line 130:     $types = entity_load('entity_test_type', FALSE, array('label' => 'label'));
 Line 134:     $types = entity_load('entity_test_type', FALSE, array('label' => 'modified'));
 Line 137:     $types = entity_load('entity_test_type', array('test', 'test2'));
 Line 143:     $types = entity_load('entity_test_type', array('test', 'test2'));
 Line 149:     $types = entity_load('entity_test_type', array('test', 'test2'));
 Line 153:     $result = entity_load('entity_test_type', array($types['test']->id));
 Line 191:     $result = entity_load('entity_test_type', array('test'));
 Line 206:     $result = entity_load('entity_test_type', array('test'));
 Line 223:     $types = entity_load('entity_test_type');
 Line 243:     $types = entity_load('entity_test_type');
 Line 880:       $return = entity_load($entity_type, array($id));

includes\entity.controller.inc (4 hits)
 Line 329:     // Call hook_entity_load().
 Line 330:     foreach (module_implements('entity_load') as $module) {
 Line 331:       $function = $module . '_entity_load';
 Line 439:         $entity->original = entity_load_unchanged($this->entityType, isset($entity->{$this->idKey}) ? $entity->{$this->idKey} : $entity->{$this->nameKey});

includes\entity.ui.inc (5 hits)
 Line 173:    *   An array of conditions as needed by entity_load().
 Line 179:     $entities = entity_load($this->entityType);
 Line 341:           $entities = entity_load($this->entityType, array($id));
 Line 398:         $entities = entity_load($this->entityType, array($id));
 Line 573:  * We don't allow numeric machine names, as entity_load() treats them as the

includes\entity.wrapper.inc (2 hits)
 Line 620:       $return = entity_load($this->type, array($this->id));
 Line 818:       $entities = entity_load($this->get(0)->type, $list);

README.txt (1 hits)
 Line 31:     entity_load(), entity_label() and entity_uri() are already provided by

tests\entity_test.module (2 hits)
 Line 70:   $types = entity_load('entity_test_type', isset($name) ? array($name) : FALSE);
 Line 90:   return entity_load('entity_test', $pids, $conditions, $reset);

BTW, is there no equivalent to Notepad++ on Linux (Ubuntu)? Shame! I started last year to increase my activities on Linux (virtual machine/server) -- before I had a 'Windows + Cygwin' client in combination with a Linux physical dev server in the LAN.

fago’s picture

This can be any entity_load() call from any module, thus this might not have to do anything with the entity api at all as also the error is in the core entity.inc include.

Blooniverse’s picture

Okay, testing the new 'Entity API 7.x-1.x-dev (2011-Jan-14)' in combination with a freshly set up Drupal7 -- together with ~70 additional modules. Results in a few minutes!

Blooniverse’s picture

Project: Entity API » Page Title
Version: 7.x-1.x-dev » 7.x-2.4-beta1
Component: Code - misc » Code
Priority: Normal » Major
Status: Postponed (maintainer needs more info) » Active

In my extensive testing environment the culprit is very clearly:

  • 'Page Title 7.x-2.4-beta1 (2010-Nov-02)' .

Adjusting issue settings correctly!

Blooniverse’s picture

Status: Active » Closed (duplicate)
stephenrobinson’s picture

I have a similar issue with images on event nodes:
Drupal 7.10, Entity API 7.x-1.0-rc1

debug from 178 includes/entity.inc:
    drupal_set_message('ids<pre>' . htmlspecialchars(print_r($ids,1)).'</pre>','error', TRUE);
    $passed_ids = !empty($ids) ? array_flip($ids) : FALSE;
    drupal_set_message('passed_ids<pre>' . htmlspecialchars(print_r($passed_ids,1)).'</pre>','error', TRUE);   



# ids

Array
(
    [0] => Array
        (
            [filename] => default_75x75.gif
            [filepath] => sites/default/files/imagefield_default_images/default_75x75.gif
            [filemime] => image/gif
            [source] => default_image_upload
            [destination] => sites/default/files/imagefield_default_images/default_75x75.gif
            [filesize] => 1387
            [uid] => 1
            [status] => 1
            [timestamp] => 1286125458
            [fid] => 313
        )

)

# Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 179 of /www/www-staging/drupal.sandbox.sanger.ac.uk/htdocs/includes/entity.inc).
# passed_ids

Array
(
)

stephenrobinson’s picture

StatusFileSize
new1.27 KB

I fixed the symptoms with a patch:

    //$passed_ids = !empty($ids) ? array_flip($ids) : FALSE; // removed
    $passed_ids=TRUE;
    if(empty($ids)){
      $passed_ids=FALSE;
    }
    else{
      foreach($ids as $key=>$value){
        if(is_array($value)){
          $passed_ids=FALSE; 
        }
      }
    }
    if($passed_ids==TRUE){
      $passed_ids=array_flip($ids);
    }
POVYLAZZZ’s picture

I tried to apply your patch but all it did was changed the error line form 177 to 191.

benheinz’s picture

Issue summary: View changes

My errors where coming from the "SPARQL API module" went away afer disabling the modules of sparkle.