Get all defined variables in PHP

Josh Sherman
1 min read
Software Development PHP

I’ve never actually used this function, but could definitely see using it to help profile a system and/or to help identify defined but unused variables.

To obtain an array of all of the defined variables you would:

$defined = get_defined_vars();

The function returns a multi-dimensional array of all of the defined variables. This is not limited to used-defined variables, so you will end up seeing server and environment variables as well.

There are also some complementary functions that allow you to get a list of the defined functions and constants, get_defined_functions() and get_defined_constants() respectively.

Have you ever used this function or know of a good use for it? Share it in the comments below, I’d love to hear about it!

Join the Conversation

Good stuff? Want more?

Weekly emails about technology, development, and sometimes sauerkraut.

100% Fresh, Grade A Content, Never Spam.

About Josh

Husband. Father. Pug dad. Musician. Founder of Holiday API, Head of Engineering and Emoji Specialist at Mailshake, and author of the best damn Lorem Ipsum Library for PHP.

Currently Reading

Parasie Eve

Previous Reads

Buy Me a Coffee Become a Sponsor

Related Articles