SOLVED: Warning: key() expects parameter 1 to be array

Hello Everyone

I have new installation Dolibarr 8.0.1 and got this error on my backend.

Warning: key() expects parameter 1 to be array, string given in /home/mydir/mydomain/core/lib/json.lib.php on line 64

I don’t know what happen cz im the new user of this platform and just try new installation.

Can you provide a screenshot ?

Hi Eldy
Thank your reply this topic.

Here’s the screenshot.

Here is the source code, from line 64 json.lib.php

// determine type
	if (is_numeric(key($elements)) && key($elements) == 0)
	{
		// indexed (list)
		$keysofelements=array_keys($elements);	// Elements array mus have key that does not start with 0 and end with num-1, so we will use this later.
		$output = '[';
		for ($i = 0, $last = ($num - 1); $i < $num; $i++)
		{
			if (! isset($elements[$keysofelements[$i]])) continue;
			if (is_array($elements[$keysofelements[$i]]) || is_object($elements[$keysofelements[$i]])) $output.= json_encode($elements[$keysofelements[$i]]);
			else $output .= _val($elements[$keysofelements[$i]]);
			if ($i !== $last) $output.= ',';
		}
		$output.= ']';
	}
	else
	{
		// associative (object)
		$output = '{';
		$last = $num - 1;
		$i = 0;
		$tmpelements=array();
		if (is_array($elements)) $tmpelements=$elements;
		if (is_object($elements)) $tmpelements=get_object_vars($elements);
		foreach($tmpelements as $key => $value)
		{
			$output .= '"'.$key.'":';
			if (is_array($value)) $output.= json_encode($value);
			else $output .= _val($value);
			if ($i !== $last) $output.= ',';
			++$i;
		}
		$output.= '}';
	}

	// return
	return $output;
}

Hi Eldy

This error from Product Module. I dont have any clue on it. I’ll try the stable version 8.0.1 and install it manually on Cpanel.

The localhost dolibarr working fine even the product module is activated.

Solved,

Thank you Eldy.

How did you solve it?

GitHub issue: Warning: key() expects parameter 1 to be array #9552

1 Like

Yes, thats my post on Github.