I am getting this error
PHP Warning: Invalid argument supplied for foreach()
for this line
{$ret = json_encode_jsfunc($value, $funcs, 1);$input[$key]=$ret[0];$funcs=$ret[1];}
Which is part of this
/**
* Function to encode JS function reference from PHP array
* http://www.php.net/manual/en/function.json-encode.php#105749
*/
function json_encode_jsfunc($input=array(), $funcs=array(), $level=0)
{
foreach($input as $key=>$value)
{
if (is_array($value))
{
$ret = json_encode_jsfunc($value, $funcs, 1);
$input[$key]=$ret[0];
$funcs=$ret[1];
}
else
{
if (substr($value,0,8)=='function')
{
$func_key="#".rand()."#";
$funcs[$func_key]=$value;
$input[$key]=$func_key;
}
// for json data, incase of local array
else if (substr($value,0,2)=='[{')
{
$func_key="#".rand()."#";
$funcs[$func_key]=$value;
$input[$key]=$func_key;
}
}
}
if ($level==1)
{
return array($input, $funcs);
}
else
{
$input_json = json_encode($input);
foreach($funcs as $key=>$value)
{
$input_json = str_replace('"'.$key.'"', $value, $input_json);
}
return $input_json;
}
}
/*
This error is transient.
It occurs in only some instances.
I've looked at the database records that are being passed into this function and there is no difference between the records that cause this issue and those that don't. However, it is always the same records that cause the error.
The code is being called from:
// multiple search group function
if ($this->actions["search"] == "group")
{
$this->options["search_options"]["multipleSearch"] = true;
$this->options["search_options"]["multipleGroup"] = true;
}
$this->options["search_options"]["sopt"] = array('eq','ne','lt','le','gt','ge','bw','bn','in','ni','ew','en','cn','nc','nu','nn');
$out = json_encode_jsfunc($this->options);
$out = substr($out,0,strlen($out)-1);
and
<?php ### P ### ?>
if (typeof(opts) != 'undefined') extra_opts = opts;
if (typeof(opts_<?php echo $grid_id?>) != 'undefined') extra_opts = opts_<?php echo $grid_id?>;
// if bootstrap, increase subgrid icon width
if (jQuery("link[href*='ui.bootstrap']").length)
extra_opts["subGridWidth"] = "33px";
var grid_<?php echo $grid_id?> = jQuery("#<?php echo $grid_id?>").jqGrid( jQuery.extend(<?php echo $out?>, extra_opts ) );
jQuery("#<?php echo $grid_id?>").jqGrid('navGrid','#<?php echo $grid_id."_pager"?>',
<?php echo json_encode_jsfunc($this->navgrid["param"])?>,
<?php echo json_encode_jsfunc($this->options["edit_options"])?>,
<?php echo json_encode_jsfunc($this->options["add_options"])?>,
<?php echo json_encode_jsfunc($this->options["delete_options"])?>,
<?php echo json_encode_jsfunc($this->options["search_options"])?>,
<?php echo json_encode_jsfunc($this->options["view_options"])?>
);
and
// Set grouping header using callGridMethod
<?php if (!empty($this->group_header)) { ?>
jQuery("#<?php echo $grid_id?>").jqGrid("setGroupHeaders", <?php echo json_encode_jsfunc($this->group_header)?>);
<?php } ?>
and also
jQuery('#<?php echo $grid_id?>').jqGrid('editGridRow', ids, <?php echo json_encode_jsfunc($this->options["edit_options"])?>);
example of a record that brings up error:
{
"idstaging" : 17,
"category" : "nutrigenetics",
"subcategory" : "methylation",
"gene" : "MTHFR",
"rs" : "rs1801133",
"taqman" : "C___1202883_20",
"var_alias" : "C677T",
"notes" : ""
}
example of a record that does NOT bring up error
{
"idstaging" : 20,
"category" : "nutrigenetics",
"subcategory" : "methylation",
"gene" : "MTRR",
"rs" : "rs1801394",
"taqman" : "C___3068176_10",
"var_alias" : "A66G",
"notes" : ""
}