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.

Willze Fortner
  • 141
  • 2
  • 2
  • 12
  • At first check that `$attrib` array contains element with key `affixes` through the[`isset()`](http://php.net/manual/en/function.isset.php) or [`array_key_exists()`](http://php.net/manual/en/function.array-key-exists.php). – Timurib Jan 03 '17 at 17:57

1 Answers1

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

Community
  • 1
  • 1
Sam Kool
  • 346
  • 2
  • 8