Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

what are global variables in PHP?

global php variables
0
Posted

what are global variables in PHP?

0

Global variables include the super-globals: $_REQUEST, $_SESSION, $_COOKIE, etc. as well as user-defined global variables through the $GLOBALS array. They are variables that can be access in any scope by use of the ‘global’ keyword (for user-defined globals) or simply by using a superglobal. The idea of having variables that can be accessed in any scope is an interesting one, and also a scary one. Although global variables can be mind-bogglingly convenient for simple problems such as passing a database layer around or accessing user information from random functions, it’s also very bad practice. But why? Well, global variables allow functions to have information that you simply don’t know about. When you call a function and pass argument to that function, you know what information that function has access to because you have specifically given it that access. When you start to use global variables, it becomes increasingly difficult to track what functions have access to what informatio

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123