Re: Classes and access to outside variables

From: Date: Sun, 30 Sep 2007 05:51:06 +0000
Subject: Re: Classes and access to outside variables
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-262589@lists.php.net to get a copy of this message
On 9/30/07, 潘志彬 <ryu.pan@gmail.com> wrote: > > $dbh = 'test'; > > class search_helper extends AjaxACApplication > { > /** > * Database connection details > */ > > // announce global variable before use it > global $dbh; > > $db_hostname = $dbh; global variables inside a class ?? as Martin said this is a bad practice. if you were going to use a global variable inside a class, why bother w/ a class in the first place? the point is to encapsulate, ie. hide implementation details from the user. by relying on a global variable, the class is open to behavior modification by external code that does not have to go through its well-defined public interface to do so. thats why its a bad practice. -nathan

« previous php.general (#262589) next »