$GLOBAL, global, and scope theory question.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

When you do:

Code: Select all

global $x;
        unset($x);
I believe you are unsetting a reference to the global var ... which is really decrementing the reference count. Whereas I believe $GLOBALS['x'] is the actual var. It is a feature of PHP variables.

Just add these to the reasons that it is not good practice to use global vars. Not much you can do because you are dealing with an existing, poorly coded, application.
(#10850)
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

arborint wrote:When you do:

Code: Select all

global $x;
        unset($x);
I believe you are unsetting a reference to the global var ... which is really decrementing the reference count. Whereas I believe $GLOBALS['x'] is the actual var. It is a feature of PHP variables.

Just add these to the reasons that it is not good practice to use global vars. Not much you can do because you are dealing with an existing, poorly coded, application.
Yes, using global is a bad practice and generates security flaws as well.
Post Reply