0

This error appears in index.php file

Warning: Illegal string offset 'id' Warning: Illegal string offset 'std'

<?php
    global $options;
    foreach ($options as $value) {
        if (get_settings( $value['id'] ) === FALSE) {
            $$value['id'] = $value['std']; 
        } else {    
            $$value['id'] = get_settings( $value['id'] ); 
        }
    }

this problem appears when trying load new theme in Wordpress...

Hady Shaltout
  • 565
  • 1
  • 5
  • 21

3 Answers3

5

For the following two things:

$value['id']
$value['std']

the variable $value is not an array but a string. And the square brackets then are substring access. Because the string is empty, you get the error message.

Demo: http://codepad.org/UDMtuO2x

hakre
  • 184,866
  • 48
  • 414
  • 792
  • actually i'm microsoft developer so i don't understand you, this bug appears when trying use wordpress theme, so can you repeat the correct code, thnx – Hady Shaltout Aug 30 '12 at 07:18
2

The [] binds stronger than the $$, i.e. php first evaluates $value['id'] and then would use this value as the name/identifier for the variable variable.
Use curly braces to change the precedence.

<?php
$array = array('id'=>123);
$value = 'array';
echo ${$value}['id'];

prints 123.

VolkerK
  • 93,904
  • 19
  • 160
  • 225
0

Its hard to say unless we know the pattern that $options hold. Try

$value->id instead of $value["id"]

WatsMyName
  • 4,016
  • 4
  • 36
  • 64