超越PHP PHP动态 | 经典文章 | CLASS | 相关下载 | 常见问题 | FORUM | WIKI | 在线手册
Site search:    
<urlencodedebug_zval_dump>
Last updated: Fri, 22 Jun 2007

CXIX. 变量函数库

简介

关于变量表现形式的信息请查看本手册 语言参考 部分的 变量 条目。

需求

无需外部库文件就可以加入本扩展模块的支持。

安装

这些函数作为 PHP 核心的一部分,无需被安装即可使用。

运行时配置

这些函数的行为受到全局配置文件 php.ini 的影响。

表格 1. 变量配置选项

名称默认值作用范围
unserialize_callback_func""PHP_INI_ALL
更多关于常量 PHP_INI_* 的细节和解释参见 ini_set()

以下是该配置选项的简要解释。

unserialize_callback_func string

如果反序列器发现有未定义类要被实例化,将会调用反序列回调函数(使用未定义类作为参数)。如果指定函数不存在,或者此函数没有包含/执行该未定义类,则显示警告。所以只有在你确实想要执行这样的回调函数时才设置该选项。

参见 unserialize()

资源类型

该扩展模块未定义任何资源类型。

预定义常量

该扩展模块未定义任何常量。

目录
debug_zval_dump -- Dumps a string representation of an internal zend value to output
doubleval -- floatval() 的别名
empty -- 检查一个变量是否为空
floatval -- 获取变量的浮点值
get_defined_vars --  返回由所有已定义变量所组成的数组
get_resource_type --  返回资源(resource)类型
gettype -- 获取变量的类型
import_request_variables -- 将 GET/POST/Cookie 变量导入到全局作用域中
intval -- 获取变量的整数值
is_array -- 检测变量是否是数组
is_bool --  检测变量是否是布尔型
is_callable --  检测参数是否为合法的可调用结构
is_double -- is_float() 的别名
is_float -- 检测变量是否是浮点型
is_int -- 检测变量是否是整数
is_integer -- is_int() 的别名
is_long -- is_int() 的别名
is_null --  检测变量是否为 NULL
is_numeric --  检测变量是否为数字或数字字符串
is_object -- 检测变量是否是一个对象
is_real -- is_float() 的别名
is_resource --  检测变量是否为资源类型
is_scalar --  检测变量是否是一个标量
is_string -- 检测变量是否是字符串
isset -- 检测变量是否设置
print_r --  打印关于变量的易于理解的信息。
serialize --  产生一个可存储的值的表示
settype -- 设置变量的类型
strval -- 获取变量的字符串值
unserialize --  从已存储的表示中创建 PHP 的值
unset -- 释放给定的变量
var_dump -- 打印变量的相关信息
var_export -- 输出或返回一个变量的字符串表示



add a note add a note User Contributed Notes
变量函数库
Darryl dot Friesen @ usask dot ca
11-Dec-2002 12:32
The above code posted by maxim and dekiland doesn't seem to create $_REQUEST in the same manner as described in the PHP Documentation:

"An associative array consisting of the contents of $_GET, $_POST, and $_COOKIE".

I modified the code slightly. I haven't tested this much, but it seems to work as expected.

$evil_vars = Array('GET', 'POST', 'COOKIE', 'SERVER', 'ENV', 'REQUEST', 'SESSION');
$php_version = preg_replace("/[^\d]/", '', phpversion());

for ($i = 0; $i < sizeof($evil_vars); $i++)
{
 if (is_array(${"HTTP_{$evil_vars[$i]}_VARS"}))
 {
   foreach (${"HTTP_{$evil_vars[$i]}_VARS"} as $var=>$val)
   {
    if($php_version<410)
     {
      $GLOBALS["_{$evil_vars[$i]}"][$var] = $val;
       // following if condition added by D. Friesen
       if (($evil_vars[$i] == 'GET') || ($evil_vars[$i] == 'POST') || ($evil_vars[$i] == 'COOKIE'))
         $GLOBALS["_REQUEST"][$var] = $val;
   }
     unset($$var); //changed from unset($$key); by dekiland
  }
 }
 unset(${"HTTP_{$evil_vars[$i]}_VARS"});
}
dekiland at rilasoft dot com
22-Mar-2002 07:55
Excellent and useful code Maxim Maletsky, but there is a small bug fix for it...

<?php

///   by Maxim Maletsky <maxim@maxim.cx>

$evil_vars = Array('GET', 'POST', 'COOKIE', 'SERVER', 'ENV', 'REQUEST',
'SESSION');
$php_version = preg_replace("/[^\d]/", '', phpversion());

for($i=0; $i<sizeof($evil_vars); $i++) {
  if(is_array(${"HTTP_{$evil_vars[$i]}_VARS"})) {
    foreach(${"HTTP_{$evil_vars[$i]}_VARS"} as $var=>$val)
{
        if($php_version<410) {
          $GLOBALS["_{$evil_vars[$i]}"][$var] = $val;
        }
       unset($$var); //changed from unset($$key); by dekiland
     }
  }
  unset(${"HTTP_{$evil_vars[$i]}_VARS"});
}

Double cheers,
dekiland
maxim at maxim dot cx
11-Mar-2002 10:22
Whoever is writing an application for a world-wide-use and wants to use $_GET etc... but cannot because of the compatibility problems, look at this peace of code.

It will help you to avoid the trouble by rewriting the variables yourself in some silly config file prepended to each script.

<?php

///   by Maxim Maletsky <maxim@maxim.cx>

$evil_vars = Array('GET', 'POST', 'COOKIE', 'SERVER', 'ENV', 'REQUEST', 'SESSION');
$php_version = preg_replace("/[^\d]/", '', phpversion());

for($i=0; $i<sizeof($evil_vars); $i++) {
  if(is_array(${"HTTP_{$evil_vars[$i]}_VARS"})) {
    foreach(${"HTTP_{$evil_vars[$i]}_VARS"} as $var=>$val) {
       if($php_version<410) {
          $GLOBALS["_{$evil_vars[$i]}"][$var] = $val;
        }
       unset($$key);
     }
  }
  unset(${"HTTP_{$evil_vars[$i]}_VARS"});
}

?>

What does it do?
It loops every $HTTP_*_VARS variable, if you run a version below 4.1.0 then it will create you a GLOBAL $_* var and will unset you the old ones.

This means that anyone on any version sending you a variable will not get it processed in the script unless it was referenced as $_*['var'].

I.E:

www.yoursite.com/file.php?some=data

<?

// that piece of code here

echo $some;  // will not come up
echo $_GET['some']  // will show up just as it would in versions above 4.1.0

function test() {
  echo $_GET['some'];   // will also work because a fake $_GET is GLOBAL
}

?>

Cheers,
Maxim Maletsky

<urlencodedebug_zval_dump>
 Last updated: Fri, 22 Jun 2007
view source | feedback | send page | sitemap | aboutus   
Copyright ® 2002-2003 PHPE.NET. All rights reserved
Last updated:2002-11-22