Unable to iterate through an object in Ubuntu PHP 5.2.10-2 Works on PHP 5.2.10?

With this code, I iterate through an object.

Works:

  • Windows with WAMP and PHP 5.2.9
  • Linux web server with PHP 5.2.10

It does not work on my desktop:

  • Ubuntu 9.10 with PHP 5.2.10-2 from repo
$incomingData = json_decode($_POST['data']);

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

}

Invalid argument provided for Eogeasp ()

0
source share
3 answers

Perhaps magic_quotes_gpc is enabled on one of your servers, so you can try using stripslashes on $ _POST ['data'] before decrypting it. Both versions of PHP should be able to iterate over objects.

+3
source

, PHP ?

foreach:

PHP 5, .

json_decode , true, json_decode , .

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

$assoc ( false) :

true, .

, PHP 5.

, $incomingData - :

$incomingData = array("foo" => "bar", "baz" => "monkey");

, .

+2

:

$data_array = get_object_vars(json_decode($json_data));

print_r($data_array);

this is only if you obtain information from some web page such as

$data = file_get_contents('http://www.someurl.com/somerestful_url/');
$ data_array = get_object_vars (json_decode ($ data));
print_r ($ data_array);

Also, you probably tried to make json_encode, but instead set json_decode ($ _ POST ['data']);

if you do not have a json string inside $ _POST ['data']; it will not work.

0
source

Source: https://habr.com/ru/post/1740427/


All Articles