• Hello,

    What does ‘ Warning: Illegal string offset ‘id’ in X on line 4 mean?
    The line 4 includes:

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

    What is wrong with this code?
    Website is https://www.vlaslant.nl

    Hope someone can help!

    Kind regards,
    Angela

Viewing 3 replies - 1 through 3 (of 3 total)
  • $$value['id'] = $value['std']; } else { $$value['id'] has one too many ‘$’s

    $$value should be $value

    other then that,,looks ok

    Thread Starter angelatjuh

    (@angelatjuh)

    Thanks,

    Changed it to one $ but still the same error.
    I did change it in both $$values, did you mean that?

    So I tried:
    <?php
    global $options;
    foreach ($options as $value) {
    if (get_settings( $value[‘id’] ) === FALSE) { $value[‘id’] = $value[‘std’]; } else { $value[‘id’] = get_settings( $value[‘id’] ); }
    }

    instead of

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

    The “Illegal string offset” warning when using $value[‘id’] means that the function is being passed a string instead of an array. (And then since a string offset is a number, ‘id’ is not suitable.)

    So in theory the problem lies elsewhere, with the caller of the code not providing a correct parameter.

    You might want to debug why the function is being given a string by examining the calling code, and find out what value it has by doing a var_dump($inputs); in the function. But for the quick solution you could change the line to:

    if (is_array($value) && get_settings( $value[‘id’] === FALSE) {

    Do it where the $value[‘id’] is, as this is a problem with php5.4, you could just revert back to 5.3 and it would be fine.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Illegal string offset 'id'’ is closed to new replies.