Is there a function to display the defined variables?

12

Is there a way to give a "var_dump" in all variables instantiated in that context, without having to put each one inside var_dump ()?

    
asked by anonymous 27.12.2013 / 11:39

2 answers

12

get_defined_vars () : Get all variables defined in print_r or var_dump to view their respective values. The value of superglobals is also returned $_POST , $_GET , $_FILE , $_SERVER , $_COOKIE , etc.

Global Scope:

<?php
$nome = 'joão';
$idade = 30;
$profissao = 'programador';
$itens = array(1,2,3,4,5,6);

$arr = get_defined_vars();

Local Scope:

<?php
function foo(){
    $local = 'exibe apenas a variavel $local';
    $arr = get_defined_vars();

    echo '<pre>';
    print_r($arr);
}

foo();

Example

    
27.12.2013 / 11:53
7

In addition to the get_defined_vars() function, mentioned in the @ lost response, in certain situations there is another one that can be very useful.

The get_defined_constants() function displays all constants defined and their values .

    
27.12.2013 / 12:14