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...

3
  • give some sample data for $option variable Commented Aug 30, 2012 at 7:03
  • Are you sure that $options has id and std as offsets? Commented Aug 30, 2012 at 7:04
  • Try foreach ($options as $value) { var_dump($value); }. Is it an array or a string? Commented Aug 30, 2012 at 7:09

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

1 Comment

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
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.

Comments

0

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.