php warning illegal string offset

Warning: Illegal string offset ‘code’

Возникает ошибка Warning: Illegal string offset ‘code’

Вот строчка из-за которой выскакивает предупреждение:

UPD: уже все работает, проблема была намного глубже в коде, чем я думал.

php warning illegal string offset. Смотреть фото php warning illegal string offset. Смотреть картинку php warning illegal string offset. Картинка про php warning illegal string offset. Фото php warning illegal string offset

1 ответ 1

Сама ошибка «Illegal string offset ‘code’» говорит вам о том, что вы пытаетесь использовать строку, как массив. Обращаетесь к неизвестному смещению ‘code’.

Для воспроизведения данной ошибки можно воспользоваться следующим кодом:

Естественно, со строкой так работать нельзя, правильное обращение к элементам строки осуществляется через число:

Смоделировать ситуацию в вашем коде легко, зададим валюту AED (Дирхам), как строку и будем пытаться ее получить:

Вывод: Warning: Illegal string offset ‘code’ on line 20

Решение проблемы:

Если дебагера нет или нет возможности им воспользоваться, то найти проблему можно с помощью внесения в код соответствующих временных изменений для получения информации о проблемном элменте. После строки, где присваивается currency добавьте проверку на is_string и сделайте вывод нужных элементов:

Вы получите вывод, где первая строка является запрашиваемым ключом, вторая строка из которой берется значение и третья это массив из которого берется значение, тем самым найдете проблемный элемент:

Далее, ищите ошибку, откуда у вас в массиве появился текстовый элемент.

Источник

Warning: Illegal string offset ‘content’

As a graphics designer I’m not too savvy when it comes to PHP code.

Warning: Illegal string offset ‘content’ in webaddress/class-vc-frontend-editor.php on line 908

I’m using the front end editor for Visual Composer and I keep getting this error coming up when inspecting the code i get the following:

I am a competent with HTML, CSS and Scripter but I’m hoping someone with advanced PHP skills will be able to answer my question.

If I open the file up in Dreamweaver to attempt to diagnose the error, I get the following:

line 908 : syntax error, unexpected quoted-string (T_CONSTANT_ENCAPSED_STRING)

What is wrong with this code so that it throws this error message up?

php warning illegal string offset. Смотреть фото php warning illegal string offset. Смотреть картинку php warning illegal string offset. Картинка про php warning illegal string offset. Фото php warning illegal string offset

3 Answers 3

Here the manual about string operators.

php warning illegal string offset. Смотреть фото php warning illegal string offset. Смотреть картинку php warning illegal string offset. Картинка про php warning illegal string offset. Фото php warning illegal string offset

It appears there are at least two errors with this code. See the list items below for explanations.

The error in the question title:

Warning: Illegal string offset ‘content’

This comes from indexing into an array that doesn’t have an offset at the specified index.

To be even safer, it might be wise to ensure that is an array with is_array():

The second error you mentioned:

line 908 : syntax error, unexpected quoted-string (T_CONSTANT_ENCAPSED_STRING)

Источник

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *