0

I am attempting to stitch together an array of objects from combining 2-3 arrays, shown here:

 while($j < $itemCounter && $i < $histCounter)
 {
     if($hists[$i]->itemid == $items[$j]->itemid)
     {
         //echo $i."\n";
         $doc[$i]->clock = intval($hists[$i]->clock); <-line 218
         $doc[$i]->value = floatval($hists[$i]->value);
         $doc[$i]->name = $items[$j]->name;
         $doc[$i]->hostname = $hostName[intval($items[$j]->hostid)];
         $i++;
     }
     else
     {
         //echo intval($hists[$i]->itemid) ."\t". intval($items[$j]->itemid)."\n";
         //echo $j."\n";
         if($hists[$i]->itemid > $items[$j]->itemid) $j++;
         else $i++;
     }
 }

And I keep getting a whole lot of these

PHP Warning: Creating default object from empty value in **.php on line 218

I also get a lot of notice lines but .. I think fixing this issue may solve my problem.

Am I doing object building completely wrong? Do I need to build a class and object and structure this totally different?

This is my declaration for $doc at the moment:

$doc = NULL;
2
  • Please, provide some data to us, only for testing purpose, and what is the line 218? Commented May 10, 2017 at 14:36
  • Hey, I have highlighted in the code, line 218 is this guy $doc[$i]->clock = intval($hists[$i]->clock); Also, what sort of data could I provide you guys with ? I am pulling history items from zabbix and merging those items with itemGet and hostGet which give more information about what historic item I just pulled and what host the item is from. I need the data in one place so this is where I create the array of merged docs. Thanks. Commented May 10, 2017 at 14:38

1 Answer 1

1

Before you start setting the clock, initiate the object.

$doc[$i] = new stdClass();
Sign up to request clarification or add additional context in comments.

1 Comment

Hey, it got rid of the warnings. Thanks friend!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.