how to list all available variable in my script

Discussion in 'PHP' started by PinoyIto, Sep 30, 2009.

  1. #1
    I have a reason why I need to do this.... It's a code related... what I want to know if possible is how I can display or list all available variables in the php file I am opening..

    For example this is the content of the a.php file

    <?php
    $a = "wala";
    $my="name.";
    echo "this is something";

    $another = "";


    ?>

    Now I want to list all available variable names at a.php, is there a way to do that...

    display the
    $a , $my, $another with out hard coding it.
     
    PinoyIto, Sep 30, 2009 IP
  2. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try this:

    <?php
    $a       = 'wala';
    $my      = 'name';
    $another = '';
    
    $defined      = get_defined_vars();
    $exclude_list = array('GLOBALS', '_ENV', 'HTTP_ENV_VARS', '_POST', 'HTTP_POST_VARS', '_GET', 'HTTP_GET_VARS', '_COOKIE', 'HTTP_COOKIE_VARS', '_SERVER', 'HTTP_SERVER_VARS', '_FILES', 'HTTP_POST_FILES', '_REQUEST');
    
    foreach ($exclude_list as $exclude) {
    	unset($defined[$exclude]);
    }
    
    echo "<pre>";
    print_r($defined);
    echo "</pre>";
    ?>
    PHP:
     
    premiumscripts, Sep 30, 2009 IP