Php 5.4 Forced line offset

in the following lines I get the error "String offset cast occured"

$code[$value['dictionaryAlias']] = $value['dictionaryText'][$codeLang]; $code[$value['dictionaryAlias']] = $value['dictionaryText'][$langDefault]; 

Actually, the access code to the table. It works in the previous version, but not in 5.4

I am new and I am responsible for code translation. What changes should I make to make it work. I read that this is probably because the variable is a string instead of an array. What can I do then?

+6
source share
1 answer

This means that $value['dictionaryText'] is a string, and either $codeLang or $langDefault not an integer. The index operator works with strings, but accepts only integer indices: when it receives something else, it tries to convert it to an integer, most often leading to a value of 0, and returns the character in that index.

This is a new warning that they introduced in 5.4 because it was a common mistake and a common cause of headaches.

+12
source

Source: https://habr.com/ru/post/945612/


All Articles