Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List all PHP variables

Is it possible to dump all global variables in a PHP script? Say this is my code:

<?php $foo = 1; $bar = "2"; include("blah.php"); dumpall(); // displays $foo, $bar and all variables created by blah.php 

Also, is it possible to dump all defined constants in a PHP script.

like image 555
Salman A Avatar asked Feb 24 '11 08:02

Salman A


People also ask

What does list () do in PHP?

The list() function is used to assign values to a list of variables in one operation. Note: Prior to PHP 7.1, this function only worked on numerical arrays.

How many variables are there in PHP?

PHP has three different variable scopes: local. global. static.

What is PHP and $$ variables?

PHP $ and $$ Variables. The $var (single dollar) is a normal variable with the name var that stores any value like string, integer, float, etc. The $$var (double dollar) is a reference variable that stores the value of the $variable inside it.

What is $_ PHP?

PHP $_POST is a PHP super global variable which is used to collect form data after submitting an HTML form with method="post". $_POST is also widely used to pass variables.


1 Answers

Use get_defined_vars and/or get_defined_constants

$arr = get_defined_vars(); print_r($arr); 
like image 152
nico Avatar answered Sep 29 '22 14:09

nico