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
  • 457
  • 1
  • 4
  • 18

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
  • 178,314
  • 47
  • 389
  • 754
  • 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
  • 92,020
  • 18
  • 157
  • 222
0

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

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

WatsMyName
  • 3,687
  • 3
  • 31
  • 58