Re: Mystery foreach error
| From: | Marco Behnke | Date: | Tue, 12 Mar 2013 21:26:54 +0000 |
| Subject: | Re: Mystery foreach error | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-320499@lists.php.net to get a copy of this message | ||
Am 12.03.13 20:45, schrieb Angela Barone:
> I've been getting the following error for awhile now, but I can't figure out why
> it's happening:
>
> Invalid argument supplied for foreach() in ... sample.php on line 377
>
> Here's that portion of code:
>
> include("states_zipcodes.php");
>
> // Check if Zip Code matches from states_zipcodes
> $zip_short = substr($zip, 0, 3);
> foreach ($states[$state] as &$zip_prefix) { // <-- line 377
what is in $states?
Looks like $states[$state] is not an array.
And don't use & reference operator in foreach loop, there can be strange
side effects if you don't act carefully with it.
> if ($zip_prefix == $zip_short) {
> break;
> } else {
> $match = 'no';
> }
> }
>
> It doesn't happen all the time, so I'm thinking that some spambot is populating the
> HTML form with something the script doesn't like(?). However, I tested that myself by entering
> text, or by entering just 2 digits, but there was no error. FYI, I do have code in the script that
> catches faulty input and warns people in their browser to go back and re-enter the correct data, so
> I'm at a loss as to why this is happening.
>
> How can I see what's triggering this to happen? I have the following line in my php.ini:
>
> error_reporting = E_ALL & E_STRICT & E_NOTICE & E_DEPRECATED
>
> Thank you,
> Angela
--
Marco Behnke
Dipl. Informatiker (FH), SAE Audio Engineer Diploma
Zend Certified Engineer PHP 5.3
Tel.: 0174 / 9722336
e-Mail: marco@behnke.biz
Softwaretechnik Behnke
Heinrich-Heine-Str. 7D
21218 Seevetal
http://www.behnke.biz
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc