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

CIII. Variablen-Funktionen

Inhaltsverzeichnis
doubleval -- Konvertiert einen Wert nach double
empty -- Pr�ft, ob eine Variable einen Wert enth�lt
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 -- Liefert den Datentyp einer Variablen
import_request_variables -- Import GET/POST/Cookie variables into the global scope
intval -- Konvertiert einen Wert nach integer
is_array -- Pr�ft, ob Variable ein Array ist
is_bool --  Pr�ft, ob eine Variable vom Typ bool ist
is_callable --  Find out whether the argument is a valid callable construct
is_double -- Pr�ft, ob eine Variable vom Typ double ist
is_float -- Pr�ft, ob eine Variable vom Typ float ist
is_int -- Pr�ft, ob eine Variable vom Typ int ist
is_integer -- Pr�ft, ob eine Variable vom Typ integer ist
is_long -- Pr�ft, ob eine Variable vom Typ long ist
is_null --  Finds whether a variable is NULL
is_numeric --  Finds whether a variable is a number or a numeric string
is_object -- Pr�ft, ob eine Variable vom Typ object ist
is_real -- Pr�ft, ob Variable vom Typ real ist
is_resource --  Pr�ft, ob eine Variable vom Typ resource ist
is_scalar --  Finds whether a variable is a scalar
is_string -- Pr�ft, ob Variable vom Typ string ist
isset -- Pr�ft die Existenz einer Variablen
print_r --  Gibt Variablen-Informationen in lesbarer Form aus
serialize --  Erzeugt ein speicherbares Datenformat
settype -- Legt den Typ einer Variablen fest
strval -- Konvertierung zum String
unserialize --  Erzeugt aus einem gespeicherten Datenformat einen Wert in PHP
unset -- L�schen einer Variablen
var_dump -- Gibt alle Informationen zu einer Variablen aus
var_export -- Outputs or returns a string representation of a variable


User Contributed Notes
Variablen-Funktionen
add a note
maxim at maxim dot cx
11-Mar-2002 04: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 <[email protected]>

$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

dekiland at rilasoft dot com
22-Mar-2002 01:55

Excellent and useful code Maxim Maletsky, but there is a small bug fix for it...

<?php

///   by Maxim Maletsky <[email protected]>

$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

Darryl dot Friesen @ usask dot ca
11-Dec-2002 06: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"});
}

bbalint at netposta dot net
17-Feb-2003 04:20

i think there's a stupidity in code: each loop you look after the
php version variable...

and i also think that $_GET won't be an autoglobal variable...
in older phpversions, the GLOBALS is the only aut-global
variable.
won't work:
 function a(){echo $_GET['data'];}
might work:
 function a(){global $_GET; echo $_GET['data'];}

add a note

<urlencodedoubleval>
 Last updated: Sat, 19 Apr 2003
show source | credits | mirror sites 
Copyright © 2001-2003 The PHP Group
All rights reserved.
This mirror generously provided by: /
Last updated: Wed May 14 01:12:44 2003 CEST