Jump to content

[SOLVED] getting the list of variables that have been defined


asmith

Recommended Posts

Hi,

 

<?php

$a = 3;
$b = 'string';
$c = array('4' => 'text');

?>

 

Where the list of the variables are stored?

I need to check some script to see what variables are in the memory.

 

I used to get that list, Something to do with globals? I've completely forgotten.

Thanks :)

Check out the following script:

 

<?php

function xyz()
{
$a = 5;
$b = 45;
$c = 38;

var_dump(get_defined_vars());
var_dump($GLOBALS);
} // end xyz();

$d = 65;

xyz();

 

The array $GLOBALS contains the list of current global variables, so it shows only the variable $d, even if we access it from the function. On the other hand, we have get_defined_vars() which returns the list of the variables in the current scope.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.