欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

Notice: Array to string conversion 在 menu_link_save() (行 3112 在 D:\xampputf8\htdocs\faq.luxshare.com\includes\menu.inc). 有大用 有大大用

修改如下  见下面红色的字,
diff --git a/core/includes/menu.inc b/core/includes/menu.inc
index f23eb0d..c6dec04 100644
--- a/core/includes/menu.inc
+++ b/core/includes/menu.inc
@@ -3085,7 +3085,18 @@ function menu_link_save(&$item, $existing_item = array(), $parent_candidates = a
   // array_intersect_assoc() with the $item as the first parameter because
   // $item may have additional keys left over from building a router entry.
   // The intersect removes the extra keys, allowing a meaningful comparison.
-  if (!$existing_item || (array_intersect_assoc($item, $existing_item)) != $existing_item) {
+  $update = TRUE;
+  if ($existing_item) {
+    $compare_left = $item;
+    $compare_right = $existing_item;
+    if ($compare_left['options'] == $compare_right['options']) {
+      unset($compare_left['options'], $compare_right['options']);
+      if (array_intersect_assoc($item, $existing_item) == $existing_item) {
+        $update = FALSE;
+      }
+    }
+  }
+  if ($update) {
     db_update('menu_links')
       ->fields(array(
         'menu_name' => $item['menu_name'],



来自  https://www.drupal.org/forum/support/installing-drupal/2012-06-08/notice-array-to-string-conversion-in-menu_link_save-line

https://www.drupal.org/files/php54_can_die_in_a_fire.patch



上面的修改好像不对,因为根本原因是 array_intersect_assoc 这个函数是不能求二维(多维数组)的交集,

我们可以  对 array_intersect_assoc 作 递归改动,改写函数如下 

如下 

function array_intersect_assoc_recursive(&$arr1, &$arr2) {
 
if (!is_array($arr1) || !is_array($arr2)) {
//      return $arr1 == $arr2; // Original line
   
return (string) $arr1 == (string) $arr2;
 }
 
$commonkeys = array_intersect(array_keys($arr1), array_keys($arr2));
 
$ret = array();
 
foreach ($commonkeys as $key) {
   
$ret[$key] =& array_intersect_assoc_recursive($arr1[$key], $arr2[$key]);
 }
 
return $ret;
}

然后 把 上面  array_intersect_assoc  的调用 改成 对 array_intersect_assoc_recursive 的调用

普通分类: