NYCPHP Meetup

NYPHP.org

[nycphp-talk] global variables

Bhulipongsanon, Pinyo Pinyo.Bhulipongsanon at usa.xerox.com
Thu May 22 14:17:09 EDT 2003


I typically use the 2nd one if I am only changing 1 variable.  I think it is
the cleanest.  I use the first, when the function changes several variables
used by several functions.

I don't use 3rd option because it is not very clear.

I know global is not too good to use a lot, but I am trying to consolidate
variables that affect the functionality of multiple files in one place so
that the program is easier to install/customize.

Pinyo

-----Original Message-----
From: Malcolm, Gary [mailto:gmalcolm at professionalcredit.com]
Sent: Thursday, May 22, 2003 1:47 PM
To: NYPHP Talk
Subject: RE: [nycphp-talk] global variables


I've been told best practice is to NOT use globals in functions, if simply
for readability but I bet we all do :) . Also, I wonder if a passed
reference to a variable is as efficient... does anyone have an opinion on
which of these is better and why (as a general rule)
1)

	$var foo;
	function  bar(&$foo){
		do stuff to change $foo
	}

2)
	var $foo = bar();
	function bar(){
		do stuff
		return a value for $foo
	}

3)
var $foo;
bar();
function bar(){
	global $foo;
	do stuff to change $foo
}




--- Unsubscribe at http://nyphp.org/list/ ---




More information about the talk mailing list