Variable that's being passed with an empty string and causing an undefined index issue in my logs

44 Views Asked by At

I know this is quite a common question but hopefully someone can provide some help for me.

/**

 * @param $optionid

 * @return mixed

 */

public function getAttributeSwatchHashcode($optionid) {
    $hashcodeData = $this->swatchHelper>getSwatchesByOptionsId([$optionid]);

    return $hashcodeData[$optionid]['value'];
}

It looks like $optionid has been passed with an empty string. So I believe I need to trace it back to getAttributeSwatchHashcode() and figure out why it's being called with no Option ID.

This is where I get a bit confused. I located it in another file.

<div class="icon" style="background-color:<?= $_helper44->getAttributeSwatchHashcode($bgColor) ?>"></div>

From what I've been reading adding a check isset($array[$index]) would be a quick fix? I'm not sure if that works in this case. Do I need to trace it back more or would that be a quick fix to get the logs to stop firing off so much?

Not sure how to include this isset condition or if it's the right place.

0

There are 0 best solutions below