array_flip():只能翻转STRING和INTEGER值!在 DrupalDefaultEntityController->load() 中
我最近将我的模块迁移到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(13)
当我错误地尝试通过 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'])).
当 Drupal 上出现此类错误时,我的建议是首先检查管理面板中的“最近日志消息”列表:
这个页面对我来说非常有帮助次。
提示:有时,不仅要查看最后一个错误,还要查看发生错误的警告和通知消息。紧接在它之前。其中一个的详细信息通常包含解决问题的重要提示。
When such errors occur on the Drupal, my suggestion is to check firstly the "Recent log messages" list in the Admin panel:
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.
您可以在翻转之前清除数组中的空值,
如下所示
You can clean the array from null values before flipping
Like this
感谢您的帖子,它对我有用!,我在 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!!
这是简单的解决方案:)
编辑
settings.php
文件并添加此行Here is simple solution :)
Edit
settings.php
file and add this line导致此错误的最常见原因是使用以数组作为参数的 some_load() 函数。不再支持此功能,因为现在需要使用 load_multiple() 函数。
D6 中的示例:
Drupal 7:
因此,捕获这些内容的最简单方法是搜索“_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:
Drupal 7:
So, the easiest way to catch these is to search for "_load(array".
我周末遇到了同样的 array_flip 错误,试图将自定义模块升级到 Drupal 7。问题是嵌套数组被传递到 DrupalDefaultEntityController 中,但它需要一个简单的整数或字符串数组。就我而言,当 EntityFieldQuery 只需要一个整数数组时,我将一个嵌套数组传递给 EntityFieldQuery。
为了更好地追踪调用DrupalDefaultEntityController的代码,请尝试在entity.inc中的第178行之前插入以下内容:
...或者最好安装Devel 模块并尝试插入以下内容:
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:
... or preferably, install the Devel module and try inserting the following instead:
当您使用有机组字段访问(有机组 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
当您使用不是实体 id 数组的数组作为第二个参数调用entity_load 时,也会发生这种情况 - 请参阅 http://api.drupal.org/api/drupal/includes--common.inc/function/entity_load/7 和 http://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.
在我们使用最新的 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/
您使用插入模块吗?请参阅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.
良好使用示例:
Example of good use:
这可能是错误编码的问题(例如加载无效实体或在 Drupal 7 中运行一些旧的 Drupal 6 代码):
故障排除:
print_r(debug_backtrace())
来转储回溯,gitk
、git log --patch
等),drush --contrib --no-empty --upgrade7x coder-review
)。或者,您可以通过定义以下临时挂钩来调试代码:
在测试之前清除缓存。
它会打印每个带有参数的 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):
Troubleshooting:
print_r(debug_backtrace())
,gitk
,git log --patch
, etc.)drush --contrib --no-empty --upgrade7x coder-review
).Alternatively you may debug your code by defining the following temporary hook:
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.