Re: [PHP] Mystery foreach error

[email protected] (Marco Behnke)
Newsgroups php.general
Message-ID <[email protected]>
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: [email protected]

Softwaretechnik Behnke
Heinrich-Heine-Str. 7D
21218 Seevetal

http://www.behnke.biz
signature.asc (application/pgp-signature, 946 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBAgAGBQJRP52gAAoJEMsuiTvEJLXOSTYP/jcGe5ugHcPGodZlAA6oQC4K
dLVJPZpT1v3MoSex5uc428lAGFl0g790Q4As7HzuFSMRW8vNSLtoYb8jBY1qXsq7
CJqg32Tkd94tWOiWgIVVWPURrU3+ewqwIuPS1fOtMGxU4ku2te/KihXHliCWf+CU
cbM0ax+a3/pg+Dx4D9aZpf3xlUOE1Zf1YokxW56xGZi4SagYor655o3EjEffE01l
veHgBgoH4Yq0QrwDrQ/B0y+OZzeUUzC8nQMdRi7n1fcxFNy1u8K6/8bLQsr1ezeP
Nf5pfrjuJAy3gvb1xMkeUycuqh7BEXSdyJis0xu9qMmOZGtG1B2l6RSTdK2fBLWN
ZfFTHmTaa3n45nKAKhW4n5Hq9Xlf1Pj6MokFzwCG5LWcyNOudufJnL5pyGz9Kd3E
UWFuk/OHiVFg0TAxVP80CoJqm41MK+fZqKsiMY3ZgMSarOT9W5FCdegCnMThUgGd
cXKwSqdQZ2PPaaRnVgU0zy4d3w5R+9Qn8xbK6bpV8k1MJYvrU9BUxSOYosgvFv6w
OG3jB//oal7NxiRmcVLA/E5smnTFcdcbllXgkVq0JDGmyFvwPMbH3dN5qTEAgnlZ
yR8W2ghzVNTJAUiRs2i+GSYTDxoii7KMHgpdzuoyRKOdiB7z/Pc1T1jQjlvIZAfe
y+XkmgPOLDFAgFo8PR7R
=lMYi
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.