views:

35

answers:

1

With this code I am iterating trough an object. Why is this working on my WAMP box with PHP 5.2.10 and isn't it on my Ubuntu 9.10 installation with PHP 5.2.10-2 from the repo's?

$incomingData = json_decode($_POST['data']);

foreach($incomingData as $key => $action)
{

}

Invalid argument supplied for foreach()

+3  A: 

wzzrd is correct. This should likely be on stackoverflow, and the issue will be with the return value from json_decode not being what you expected.

From http://php.net/json_decode

Returns the value encoded in json in appropriate PHP type. Values true, false and null (case-insensitive) are returned as TRUE, FALSE and NULL respectively. NULL is returned if the json cannot be decoded or if the encoded data is deeper than the recursion limit.

Are you making the same request on both servers (&data=xxx is exactly the same)? That'd be the first thing to verify.

Assuming yes, are your php.ini's similar?

magic_quotes_gpc=1 will alter $_GET/$_POST/$_COOKIE and is the likely culprit.