无法遍历 Ubuntu PHP 5.2.10-2 中的对象是否适用于 PHP 5.2.10? [英] Cannot iterate through object in Ubuntu PHP 5.2.10-2 Works on PHP 5.2.10?

查看:45
本文介绍了无法遍历 Ubuntu PHP 5.2.10-2 中的对象是否适用于 PHP 5.2.10?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用这段代码,我正在遍历一个对象.

作品:

  • 带有 WAMP 和 PHP 5.2.9 的 Windows
  • 使用 PHP 5.2.10 的 Linux 网络服务器

它在我的桌面上不起作用:

  • Ubuntu 9.10 和 PHP 5.2.10-2 来自回购的
<块引用>

$incomingData = json_decode($_POST['data']);foreach($incomingData as $key => $action){}

提供了无效的参数foreach()

解决方案

也许你的一台服务器启用了 magic_quotes_gpc,所以你可以在解码之前尝试在 $_POST['data'] 上使用斜杠.两个 PHP 版本都应该能够遍历对象.

With this code I am iterating through an object.

Works:

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

It is not working on my desktop:

  • Ubuntu 9.10 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()

解决方案

Maybe one of your servers has magic_quotes_gpc enabled, so you can try to use stripslashes on $_POST['data'] before you decode it. Both PHP versions should be able to iterate through objects.

这篇关于无法遍历 Ubuntu PHP 5.2.10-2 中的对象是否适用于 PHP 5.2.10?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆