PHP Warning: reset(): Passed variable is not an array or object

Message:

PHP Warning: reset(): Passed variable is not an array or object in /home/cron.php on line 43

Error type: warning

Symptoms:

You get a reset() warning although the code seems to work fine.

Sample Code:

<?php
$string = “This is a string.”;
reset($string);
?>

Cause:

You try to use the reset() function with a null, an integer or a string (these are most common), when you should only use it with an array or object. Usually this is caused by accidental type casting or misspelling of variable names.

Fix:

Make sure the variable you try to reset exists and is not null first. You should also make sure you didn’t misspell the variable name (if you try to reset a variable that has not been initialized you get the same warning).

One Response

  1. Alaa Says:

    hi
    how are you?

Leave a Reply

Your email address will not be published. Required fields are marked *