array_flip():只能翻转STRING和INTEGER值!在 DrupalDefaultEntityController->load() 中

发布于 2024-10-14 02:55:30 字数 3119 浏览 4 评论 0原文

我最近将我的模块迁移到 Drupal7(在 PHP 版本 5.3.1 上),现在我收到以下错误:

    * Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of C:\Users\akulkarni\Desktop\xampp\htdocs\servicecasting\includes\entity.inc).
    * Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of C:\Users\akulkarni\Desktop\xampp\htdocs\servicecasting\includes\entity.inc).
    * Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of C:\Users\akulkarni\Desktop\xampp\htdocs\servicecasting\includes\entity.inc).
    * Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->cacheGet() (line 354 of C:\Users\akulkarni\Desktop\xampp\htdocs\servicecasting\includes\entity.inc).
    * Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of C:\Users\akulkarni\Desktop\xampp\htdocs\servicecasting\includes\entity.inc).
    * Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->cacheGet() (line 354 of C:\Users\akulkarni\Desktop\xampp\htdocs\servicecasting\includes\entity.inc).
    * Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of C:\Users\akulkarni\Desktop\xampp\htdocs\servicecasting\includes\entity.inc).
    * Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->cacheGet() (line 354 of C:\Users\akulkarni\Desktop\xampp\htdocs\servicecasting\includes\entity.inc).

我还尝试将其他模块和核心升级到此处提到的最新版本 http://drupal.org/node/1022736

实体7.x-1.x-dev(2011年1月24日), 视图 7.x-3.x-dev(2011 年 1 月 22 日), Drupal 核心 7.x-dev(2011 年 1 月 24 日), 配置文件2 7.x-1.0-beta1, 参考文献 7.x-2.x-dev (2011-Jan-14), ctools 7.x-1.0-alpha2

我无法弄清楚到底是什么导致了这个错误?

编辑:

根据http://php.net/manual/en/function .array-flip.php,

array_flip() 返回一个翻转顺序的数组,即来自 trans 的键 变成值,反式的值变成键。

请注意,trans 的值必须是有效的键,即它们必须是整数或字符串。如果出现以下情况,将会发出警告 值的类型错误,并且相关的键/值对不会 被翻转。

我已经在entity.inc中第178行之前完成了var_dump($ids); ($passed_ids = !empty($ids) ? array_flip($ids) : FALSE;

在我看来,键/值对始终采用正确的格式(?)。

array
  0 => 
    array
      'nid' => string '6' (length=1)

array
  0 => 
    array
      'uid' => string '1' (length=1)

array
  0 => string '0' (length=1)

array
  0 => 
    array
      'nid' => string '7' (length=1)

array
  0 => 
    array
      'nid' => string '4' (length=1)

array
  0 => 
    array
      'nid' => string '8' (length=1)

I have recently migrated my module to Drupal7 (on PHP Version 5.3.1) and now I am getting following errors:

    * Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of C:\Users\akulkarni\Desktop\xampp\htdocs\servicecasting\includes\entity.inc).
    * Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of C:\Users\akulkarni\Desktop\xampp\htdocs\servicecasting\includes\entity.inc).
    * Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of C:\Users\akulkarni\Desktop\xampp\htdocs\servicecasting\includes\entity.inc).
    * Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->cacheGet() (line 354 of C:\Users\akulkarni\Desktop\xampp\htdocs\servicecasting\includes\entity.inc).
    * Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of C:\Users\akulkarni\Desktop\xampp\htdocs\servicecasting\includes\entity.inc).
    * Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->cacheGet() (line 354 of C:\Users\akulkarni\Desktop\xampp\htdocs\servicecasting\includes\entity.inc).
    * Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of C:\Users\akulkarni\Desktop\xampp\htdocs\servicecasting\includes\entity.inc).
    * Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->cacheGet() (line 354 of C:\Users\akulkarni\Desktop\xampp\htdocs\servicecasting\includes\entity.inc).

I have also tried upgrading other modules and core to latest versions as mentioned here http://drupal.org/node/1022736

entity 7.x-1.x-dev (2011-Jan-24),
views 7.x-3.x-dev (2011-Jan-22),
Drupal core 7.x-dev (2011-Jan-24),
profile2 7.x-1.0-beta1,
references 7.x-2.x-dev (2011-Jan-14),
ctools 7.x-1.0-alpha2

I am not able to figure out what is exactly causing this error?

Edit:

According to http://php.net/manual/en/function.array-flip.php,

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.

I have done the var_dump($ids); before line 178 in entity.inc ( $passed_ids = !empty($ids) ? array_flip($ids) : FALSE;)

And it looks to me that key/value pair is always in correct format(?).

array
  0 => 
    array
      'nid' => string '6' (length=1)

array
  0 => 
    array
      'uid' => string '1' (length=1)

array
  0 => string '0' (length=1)

array
  0 => 
    array
      'nid' => string '7' (length=1)

array
  0 => 
    array
      'nid' => string '4' (length=1)

array
  0 => 
    array
      'nid' => string '8' (length=1)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(13

深海夜未眠 2024-10-21 02:55:30

当我错误地尝试通过 node_load_multiple($nids) 加载多个节点时,我也收到了此消息,其中 $nids 不是节点 ID 数组。

例如,使用 EntityFieldQuery 的结果,并调用 node_load_multiple($result['node']) 而不是node_load_multiple(array_keys($result['node']))。

I've also gotten this message when erroneously trying to load multiple nodes via node_load_multiple($nids) where $nids was not an array of node-ids.

For example, using the result of an EntityFieldQuery, and calling node_load_multiple($result['node']) instead of node_load_multiple(array_keys($result['node'])).

她说她爱他 2024-10-21 02:55:30

当 Drupal 上出现此类错误时,我的建议是首先检查管理面板中的“最近日志消息”列表

在此处输入图像描述

这个页面对我来说非常有帮助次。

提示:有时,不仅要查看最后一个错误,还要查看发生错误的警告通知消息。紧接在它之前。其中一个的详细信息通常包含解决问题的重要提示。

When such errors occur on the Drupal, my suggestion is to check firstly the "Recent log messages" list in the Admin panel:

enter image description here

This page has been very helpful to me many times.

Tip: Sometimes it makes sense to look at not only the last Error but also the Warning and Notice messages that immediately precede it. Details of one of them usually contain a significant hint to solve the problem.

绅刃 2024-10-21 02:55:30

您可以在翻转之前清除数组中的空值,

如下所示

$my_array = array_filter($my_array);
$my_array = array_flip($my_array);

You can clean the array from null values before flipping

Like this

$my_array = array_filter($my_array);
$my_array = array_flip($my_array);
傲世九天 2024-10-21 02:55:30

感谢您的帖子,它对我有用!,我在 Drupal 7 中遇到这个问题很长时间了,并且可以解决这个问题。底线

“不要将任何类型的实体的数组值传递给 array_flip,
例如:如果您尝试加载实体 user_load() 或 field_collection_item_load() 来加载字段集合项,请仅传递字符串中的值而不是数组本身。”

谢谢!!

Thanks for the post it worked for me!, I was encountering with this problem in Drupal 7 since long time and could fighure out the problem. Bottom line

"Do not pass array values to array_flip for any kind of entities,
eg: If you are trying to load and entity user_load() or field_collection_item_load() for loading field collection items, Pass only values in the string rather than array itself."

Thanks!!

薄情伤 2024-10-21 02:55:30

这是简单的解决方案:)

编辑 settings.php 文件并添加此行

error_reporting(0);

Here is simple solution :)

Edit settings.php file and add this line

error_reporting(0);
泪冰清 2024-10-21 02:55:30

导致此错误的最常见原因是使用以数组作为参数的 some_load() 函数。不再支持此功能,因为现在需要使用 load_multiple() 函数。

D6 中的示例:

<?php
// Using array with the id was already discouraged in D6 but still worked.
$user = user_load(array('uid' => 1));
$user = user_load(array('name' => 'admin'));
?>

Drupal 7:

<?php
// Argument to a load() function *must* be a single id
$user = user_load(1);

// Querying for another attribute is a bit more complex.
// Note that using reset(user_load_multiple() directly is not E_STRICT compatible.
$users = user_load_multiple(array(), array('name' => 'admin'));
$user = reset($users);
?>

因此,捕获这些内容的最简单方法是搜索“_load(array”。

The most common cause of this error is using a something_load() function with an array as argument. This is not supported anymore because the load_multiple() functions need to be used for this now.

Example in D6:

<?php
// Using array with the id was already discouraged in D6 but still worked.
$user = user_load(array('uid' => 1));
$user = user_load(array('name' => 'admin'));
?>

Drupal 7:

<?php
// Argument to a load() function *must* be a single id
$user = user_load(1);

// Querying for another attribute is a bit more complex.
// Note that using reset(user_load_multiple() directly is not E_STRICT compatible.
$users = user_load_multiple(array(), array('name' => 'admin'));
$user = reset($users);
?>

So, the easiest way to catch these is to search for "_load(array".

天赋异禀 2024-10-21 02:55:30

我周末遇到了同样的 array_flip 错误,试图将自定义模块升级到 Drupal 7。问题是嵌套数组被传递到 DrupalDefaultEntityController 中,但它需要一个简单的整数或字符串数​​组。就我而言,当 EntityFieldQuery 只需要一个整数数组时,我将一个嵌套数组传递给 EntityFieldQuery。

为了更好地追踪调用DrupalDefaultEntityController的代码,请尝试在entity.inc中的第178行之前插入以下内容:

drupal_set_message(var_export(debug_backtrace(), TRUE));

...或者最好安装Devel 模块并尝试插入以下内容:

dpm( debug_backtrace() );

I ran into the same array_flip error over the weekend, trying to upgrade a custom module to Drupal 7. The problem is that a nested array is getting passed into DrupalDefaultEntityController, but it's expecting a simple array of integers or strings. In my case, I was passing in a nested array in to EntityFieldQuery, when it wants just an array of integers.

To better track down the code that is calling DrupalDefaultEntityController, try inserting the following before line 178 in entity.inc:

drupal_set_message(var_export(debug_backtrace(), TRUE));

... or preferably, install the Devel module and try inserting the following instead:

dpm( debug_backtrace() );
戏剧牡丹亭 2024-10-21 02:55:30

当您使用有机组字段访问(有机组 7.x-1.3)时,就会出现问题。

您通常可以禁用该子模块,除非您使用 OG 进行字段级访问控制。

http://drupal.org/node/1102570#comment-5626946

The problem comes up when you're using Organic groups field access (Organic Groups 7.x-1.3)

You can usually disable that sub-module unless you do field level access control with OG.

http://drupal.org/node/1102570#comment-5626946

ㄟ。诗瑗 2024-10-21 02:55:30

当您使用不是实体 id 数组的数组作为第二个参数调用entity_load 时,也会发生这种情况 - 请参阅 http://api.drupal.org/api/drupal/includes--common.inc/function/entity_load/7http://drupal.org/node/1160566 了解原因。

This can also happen when you call entity_load with an array that is not an array of entity id's as the second argument - see http://api.drupal.org/api/drupal/includes--common.inc/function/entity_load/7 and http://drupal.org/node/1160566 to understand why.

凉月流沐 2024-10-21 02:55:30

在我们使用最新的 page_title 模块时看到了类似的问题。目前,我们只是禁用了该模块并清除了错误。

请参阅:http:// www.newblood.com/blog/2011/04/26/drupal-7-error-in-page-title-module/

Saw a similar issue in our usage of the latest page_title module. For now, we just disabled the module and it cleaned up the error.

See: http://www.newblood.com/blog/2011/04/26/drupal-7-error-in-page-title-module/

缱绻入梦 2024-10-21 02:55:30

您使用插入模块吗?请参阅http://drupal.org/node/850946

当涉及到像这样的特定错误时,我认为您最好在 drupal.org 上搜索问题队列,而不是在所以。

Are you using Insert Module? See http://drupal.org/node/850946.

When it comes to specific errors like this, I think you're better off searching the issue queue at drupal.org than asking on SO.

人事已非 2024-10-21 02:55:30

良好使用示例:

<?php
$user=user_load(arg(1));
$username=$user->name;
print strtolower(preg_replace('/[^a-zA-Z0-9\-]/si' , '-' , $username));
?>

Example of good use:

<?php
$user=user_load(arg(1));
$username=$user->name;
print strtolower(preg_replace('/[^a-zA-Z0-9\-]/si' , '-' , $username));
?>
枕梦 2024-10-21 02:55:30

这可能是错误编码的问题(例如加载无效实体或在 Drupal 7 中运行一些旧的 Drupal 6 代码):

  • 如果您有任何自定义模块,请仔细检查您的代码是否存在常见错误
  • 如果您正在使用 contrib 模块,找到针对它的正确错误并应用补丁(如果可用)或提出新补丁。

故障排除:

  • 您可以尝试通过调用并打印 print_r(debug_backtrace()) 来转储回溯,
  • 使用 scm 工具返回到正常工作的点,并比较更改,因此最终您会找到问题所在(例如 gitkgit log --patch 等),
  • 请使用 Coder Review 模块,用于在更新后查找代码中的错误(例如 drush --contrib --no-empty --upgrade7x coder-review )。
  • 安装 XDebug 通过跟踪日志或逐步调试来跟踪您的问题。

或者,您可以通过定义以下临时挂钩来调试代码:

/**
 * Implements hook_watchdog().
 */
function foo_watchdog($log_entry) {
  if ($log_entry['type'] == 'php' && $log_entry['severity'] <= WATCHDOG_WARNING) {
    // Old school
    var_dump(debug_backtrace()); // Optionally add: exit();

    // Devel: Log the backtrace into temporary file: drupal_debug.txt
    // Locate via: $ drush eval "echo file_directory_temp() . '/drupal_debug.txt'"
    function_exists('dd') && dd(debug_backtrace());
  }
}

在测试之前清除缓存。

它会打印每个带有参数的 PHP 警告或错误的回溯,以便您可以找到传递到 Drupal 核心的无效参数。

This could be problem of the bad coding (e.g. loading invalid entities or running some old Drupal 6 code in Drupal 7):

  • If you've any custom modules, double check your code for common mistake
  • If you're using contrib module, find the right bug against it and apply the patch (if available) or raise the new one.

Troubleshooting:

  • You may try to dump the backtrace by calling and printing print_r(debug_backtrace()),
  • Use your scm tool to get back to the point where it was working fine, and compare the changes, so eventually you'll find where the problem is (e.g. gitk, git log --patch, etc.)
  • please use Coder Review module to find bugs in your code after the update (e.g. drush --contrib --no-empty --upgrade7x coder-review).
  • Install XDebug to track your issue by trace log or step-by-step debugging.

Alternatively you may debug your code by defining the following temporary hook:

/**
 * Implements hook_watchdog().
 */
function foo_watchdog($log_entry) {
  if ($log_entry['type'] == 'php' && $log_entry['severity'] <= WATCHDOG_WARNING) {
    // Old school
    var_dump(debug_backtrace()); // Optionally add: exit();

    // Devel: Log the backtrace into temporary file: drupal_debug.txt
    // Locate via: $ drush eval "echo file_directory_temp() . '/drupal_debug.txt'"
    function_exists('dd') && dd(debug_backtrace());
  }
}

Clear the cache before testing it.

It'll print the backtrace on every PHP warning or error with arguments, so you can find your invalid parameters which were passed into the Drupal core.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文