Re: Coding Practice: Use global $var or pass in by refernce

From: Date: Fri, 03 Mar 2006 18:51:29 +0000
Subject: Re: Coding Practice: Use global $var or pass in by refernce
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-231408@lists.php.net to get a copy of this message
----- Original Message ----- From: "Mark Steudel" <mark@netriver.net> To: <php-general@lists.php.net> Sent: Friday, March 03, 2006 7:46 PM Subject: [PHP] Coding Practice: Use global $var or pass in by refernce
I was wondering what the general rule on using the global driective versus passing in a variable by reference, why you should or shouldn't, etc. e.g. function () { global $db; $res =& $db->query( "SQL"); } or function ( &$db ) { $res =& $db->query( "SQL"); } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Hi!
My oponion is that is insane to use global variables. The main drawback with global variables is that is very easy to mix up variables, and keep track of what variable belongs to what. So an advice: Don't use it! /G

« previous php.general (#231408) next »