3

I get illegal string offset warning from the array inside if statement

411.  if (is_array($attrib['affixes'])) { // merge
412.     $new_affix = array_merge($attrib['affixes'], $new_affix);
413.  }

Exactly the warning is

"Warning: Illegal string offset 'affixes' in C:\xampp\htdocs\pengakar-master\src\Pengakar.php on line 411"

I insert the full code below :

http://ideone.com/QQEdCu

Another part is alright. Only that part that get the error

Thanks for the help.

1
  • At first check that $attrib array contains element with key affixes through theisset() or array_key_exists(). Commented Jan 3, 2017 at 17:57

1 Answer 1

5

The illegal offset means that the index your are referencing does not exist. So, in this case the 'affixes' index of the array is never defined. To prevent the error, change the code as follows:

if (isset($attrib['affixes']) && is_array($attrib['affixes'])) { // merge
    $new_affix = array_merge($attrib['affixes'], $new_affix);
}

Look over here for more information about the error: Illegal string offset Warning PHP

Sign up to request clarification or add additional context in comments.

Comments

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.