0

I don't find a reason why the offset is considered illegal in the code snippet. Any suggestion to fix this with an explanation why the error occurs is greatly appreciated.

    foreach ($my_return->refund_items as $key => $my_refund_item) {
        $refund_item_info = $my_return->get_line_item_info($my_refund_item['lineitem_fk']);
        if ($refund_item_info['order_fk'] != 0)
            $my_refund_item['sku'] = $refund_item_info['sku'];
        $refund_items_array[] = $my_refund_item;
    }
1
  • you need to first check using the print_r($refund_item_info) or check there is order_fk key exist or not in $refund_item_info array. Jul 7 '20 at 18:14
1

To answer your question why the warning "PHP Warning: Illegal string offset order_fk" is thrown. This warning indicates that probably you are treating a string object as associative array. Although you could treat string as array where index can be applied like [0] or [1] to get individual characters from string but not as associative array where key is string.

Now to solve you problem, as Rasik mentioned in comment, first you need to print $refund_item_info to check what is exact content of it also check its type by echo gettype($refund_item_info).

Additionally to let you know, check if value is json, since json is considered as string, so you need to convert a json string into array by $str = json_decode($str, true); before accessing its keys.

Hope it helps you. Thanks

2
  • I shall do as advised. Accepted your answer as it enlightens me on the underlying concepts. Thanks Abdul. Jul 8 '20 at 9:17
  • Most Welcome :) Jul 8 '20 at 9:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.