• map_deep ( mixed $value, callable $callback )

    Having just upgraded to 4.4 I am now getting an error when calling urlencode.

    This function now calls this new map_deep function and is giving an error: –

    Fatal error: An iterator cannot be used with foreach by reference in /home/domain/public_html/domain/wp-includes/formatting.php on line 3896

    A foreach iteration was not done in previous versions i.e urlencode_deep was simply returning an array but now calls map_deep and this uses a foreach iteration.

    Code that initiated this error: –

    foreach( $submit_vars as $key => $value ) $fields .= "$key=" . urlencode( $value ) . "&";

Viewing 4 replies - 1 through 4 (of 4 total)
  • I am also getting the same error:
    Fatal error: An iterator cannot be used with foreach by reference in /x/wp-includes/formatting.php on line 3896

    I am writing a custom importer from an xml feed.

    EDIT:
    Fixed my problem. one the the vars i was passing was an empty object.
    I thought it was a str. A quick if to swap the empty obj to a empty str fixed all problems.

    Thread Starter markethive

    (@markethive)

    Can you give an example of the fix you made ?

    Sure thing
    I found that a XML variable was blank, when it was made into a php variable it was an empty object, like this.

    $color = $g['color'];
    var_dump($color);

    Returned object(SimpleXMLElement)#396 (0) { }
    So all i did was a simple shorthand if statement.
    This fixed my problem:

    $color = $g['color'] ? $g['color'] : '';

    Now the var_dump returns string(0) ""

    This was the line that was triggering the error

    update_post_meta( $post_id, 'color', $color );

    Hope this helps!

    Thread Starter markethive

    (@markethive)

    Thanks, appreciate you taking the time to respond.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘4.4 upgrade giving Fatal Error in formatting.php line 3896’ is closed to new replies.