Forum Moderators: coopster

Message Too Old, No Replies

PHP configuration problem?

foreach not working properly

         

zeeshan_kh

10:40 am on Jan 5, 2006 (gmt 0)

10+ Year Member



Hey,

I have got PHP 4.3.10 Installed on my local system (windows) and server (Fedora).

foreach loop runs perfectly on my local system but it gives me problems on the server.

here is a sample code.


$FilenameParameters1 = array('ar', 'bg', 'bc', 'far');
foreach ($FilenameParameters1 as $key) {
echo $key;
}

on local system it prints the values
"ar bg bc far"

but on the server it prints
"Array Array Array Array"

it works fine if i change $key to $k=>$key in the loop. Because of that i'm not able to run any libraries or classes downloaded from the internet.

please HELP me sort this out.

Thanks

coopster

2:32 pm on Jan 5, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



For a simple snippet of code like that not to work is certainly fishy. I cannot recall if there was bug back in that release ...? I know PHP4 has been patched 3 times since the release you are running though. Anybody else run into this or remember bugs with the foreach() function at this release level?

zeeshan_kh

3:06 pm on Jan 5, 2006 (gmt 0)

10+ Year Member



it is a configuration issue for sure becuase i always get this probelm when i upload any code including foreach..i always have to change all foreach($arr as $val) loops to foreach($arr as $key=>$val)

jatar_k

4:29 pm on Jan 5, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I don't remember the release but there were a couple of fixes to foreach

very strange but I am having a hard time thinking it is a conf issue, not sure how conf could do that.

zeeshan_kh

5:10 pm on Jan 5, 2006 (gmt 0)

10+ Year Member



yea i've just matched my local php.ini file where foreach works fine with my server php.ini file and didnt find anything different..

do you guyz think its just an issue with the version of php. Because i can update the php version but i'm just concerned will it, in any way, effect sites running on it?

Thanks

coopster

5:20 pm on Jan 5, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Well, I definitely remember there being a bug issue with foreach() somewhere down the changelogs but cannot recall which version it was or if it was also closely related to the OS, HTTP server version, etc. combination.

Even so, if you are able to patch the PHP version you are likely better off than where you stand now, no?

zeeshan_kh

10:50 am on Jan 6, 2006 (gmt 0)

10+ Year Member



ok thanks for you help guyz.. i'll try to install 4.4.1 today and see what happens.