PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<urlencodedoubleval>
view the version of this page
Last updated: Thu, 21 Aug 2003

CV. Variable Functions

Introduction

For information on how variables behave, see the Variables entry in the Language Reference section of the manual.

Requirements

No external libraries are needed to build this extension.

Installation

There is no installation needed to use these functions; they are part of the PHP core.

Runtime Configuration

The behaviour of these functions is affected by settings in php.ini.

Table 1. Variables Configuration Options

NameDefaultChangeable
unserialize_callback_func""PHP_INI_ALL
For further details and definition of the PHP_INI_* constants see ini_set().

Here's a short explanation of the configuration directives.

unserialize_callback_func string

The unserialize callback function will called (with the undefind class' name as parameter), if the unserializer finds an undefined class which should be instanciated. A warning appears if the specified function is not defined, or if the function doesn't include/implement the missing class. So only set this entry, if you really want to implement such a callback-function.

See also unserialize().

Resource Types

This extension has no resource types defined.

Predefined Constants

This extension has no constants defined.

Table of Contents
doubleval -- Alias of floatval()
empty -- Determine whether a variable is empty
floatval -- Get float value of a variable
get_defined_vars --  Returns an array of all defined variables
get_resource_type --  Returns the resource type
gettype -- Get the type of a variable
import_request_variables -- Import GET/POST/Cookie variables into the global scope
intval -- Get integer value of a variable
is_array -- Finds whether a variable is an array
is_bool --  Finds out whether a variable is a boolean
is_callable --  Verify that the contents of a variable can be called as a function
is_double -- Alias of is_float()
is_float -- Finds whether a variable is a float
is_int -- Find whether a variable is an integer
is_integer -- Alias of is_int()
is_long -- Alias of is_int()
is_null --  Finds whether a variable is NULL
is_numeric --  Finds whether a variable is a number or a numeric string
is_object -- Finds whether a variable is an object
is_real -- Alias of is_float()
is_resource --  Finds whether a variable is a resource
is_scalar --  Finds whether a variable is a scalar
is_string -- Finds whether a variable is a string
isset -- Determine whether a variable is set
print_r --  Prints human-readable information about a variable
serialize --  Generates a storable representation of a value
settype -- Set the type of a variable
strval -- Get string value of a variable
unserialize --  Creates a PHP value from a stored representation
unset -- Unset a given variable
var_dump -- Dumps information about a variable
var_export -- Outputs or returns a string representation of a variable


add a note add a note User Contributed Notes
Variable Functions
Darryl dot Friesen @ usask dot ca
11-Dec-2002 03: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 10: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 01: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

<urlencodedoubleval>
 Last updated: Thu, 21 Aug 2003
show source | credits | sitemap | mirror sites 
Copyright © 2001-2003 The PHP Group
All rights reserved.
This mirror generously provided by: http://php.mirrors.ilisys.com.au/
Last updated: Sat 01 Nov 2003 04:13:36 EST EST