免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2002 | 回复: 4
打印 上一主题 下一主题

请教一个奇怪的调用问题!! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-12 19:55 |只看该作者 |倒序浏览
本帖最后由 newtopqjh 于 2011-12-12 19:57 编辑
  1. <?php
  2. // set true if production environment else false for development
  3. define ('IS_ENV_PRODUCTION', true);

  4. // configure error reporting options
  5. error_reporting(E_ALL | E_STRICT);
  6. ini_set('display_errors', !IS_ENV_PRODUCTION);
  7. ini_set('error_log', 'log/phperror.txt');
  8. // set time zone to use date/time functions without warnings
  9. date_default_timezone_set('America/New_York');

  10. // compensate for magic quotes if necessary
  11. if (get_magic_quotes_gpc())
  12. {
  13.     function _stripslashes_rcurs($variable, $top = true)
  14.     {
  15.         $clean_data = array();
  16.         foreach ($variable as $key => $value)
  17.         {
  18.             $key = ($top) ? $key : stripslashes($key);
  19.             $clean_data[$key] = (is_array($value)) ?
  20.                stripslashes_rcurs($value, false) : stripslashes($value);
  21.         }
  22.         return $clean_data;
  23.     }
  24.     $_GET = _stripslashes_rcurs($_GET);
  25.     $_POST = _stripslashes_rcurs($_POST);
  26.     // $_REQUEST = _stripslashes_rcurs($_REQUEST);
  27.     // $_COOKIE = _stripslashes_rcurs($_COOKIE);
  28. }
  29. ?>
复制代码
上面代码中的函数定义是 _stripslashes_rcurs($variable, $top = true),但函数体内的递归调用却是stripslashes_rcurs($value, false),而stripslashes_rcurs()却不是PHP内置的函数,以上代码完全能正常运行,这是怎么会事?

论坛徽章:
0
2 [报告]
发表于 2011-12-12 21:02 |只看该作者
这段肯定是错的,把_stripslashes_rcurs打成了stripslashes_rcurs

但是这个错误触发条件很苛刻,近几年的php版本已经默认关掉gpc了,也就是说, 那一段里一般是不会运行的,即使人工开启了gpc,也必须符合GET,POST的数组里某个键的值是数组才能触发,所以一般情况运行会不报错

论坛徽章:
0
3 [报告]
发表于 2011-12-13 09:57 |只看该作者
本帖最后由 newtopqjh 于 2011-12-13 10:02 编辑
这段肯定是错的,把_stripslashes_rcurs打成了stripslashes_rcurs

但是这个错误触发条件很苛刻,近几年的 ...
3227049 发表于 2011-12-12 21:02



    首先谢谢你的回答。
但情况是这样的如果把if (get_magic_quotes_gpc())换成if (!get_magic_quotes_gpc()):
  1. <?php
  2. // set true if production environment else false for development
  3. define ('IS_ENV_PRODUCTION', true);

  4. // configure error reporting options
  5. error_reporting(E_ALL | E_STRICT);
  6. ini_set('display_errors', !IS_ENV_PRODUCTION);
  7. ini_set('error_log', 'log/phperror.txt');
  8. // set time zone to use date/time functions without warnings
  9. date_default_timezone_set('America/New_York');

  10. // compensate for magic quotes if necessary
  11. if (!get_magic_quotes_gpc())
  12. {
  13.     function _stripslashes_rcurs($variable, $top = true)
  14.     {
  15.         $clean_data = array();
  16.         foreach ($variable as $key => $value)
  17.         {
  18.             $key = ($top) ? $key : stripslashes($key);
  19.             $clean_data[$key] = (is_array($value)) ?
  20.                stripslashes_rcurs($value, false) : stripslashes($value);
  21.         }
  22.         return $clean_data;
  23.     }
  24.     $_GET = _stripslashes_rcurs($_GET);
  25.     $_POST = _stripslashes_rcurs($_POST);
  26.     // $_REQUEST = _stripslashes_rcurs($_REQUEST);
  27.     // $_COOKIE = _stripslashes_rcurs($_COOKIE);
  28. }

  29. echo"<a href=".$_SERVER['PHP_SELF']."?a=it's my \"kid\" dog!">测试</a>

复制代码
一样正常运行。这个例子是.Wrox.PHP.and.MySQL.Create.Modify.Reuse.May.2008.pdf书中的第1个例子。附件如下(代码位于lib目录下的 commin.php)

192429_ch01_code.zip

12.46 KB, 下载次数: 0

论坛徽章:
0
4 [报告]
发表于 2011-12-13 10:13 |只看该作者
首先谢谢你的回答。
但情况是这样的如果把if (get_magic_quotes_gpc())换成if (!get_magic_quot ...
newtopqjh 发表于 2011-12-13 09:57



你忽略了我那句也必须符合GET,POST的数组里某个键的值是数组才能触发

你把

  1. $_GET=array("test"=>array("hello"=>array("world"));

  2. if (1)
复制代码
替换掉

  1. if (get_magic_quotes_gpc())
复制代码
就能成功触发错误了

无论电子还是实体的出版物出现typo错都很正常的

论坛徽章:
0
5 [报告]
发表于 2011-12-13 10:30 |只看该作者
谢谢,正如你说的那样!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP