Re: [PHP] Classes and access to outside variables
- From: quickshiftin@xxxxxxxxx ("Nathan Nobbe")
- Date: Sun, 30 Sep 2007 01:51:06 -0400
On 9/30/07, 潘志彬 <ryu.pan@xxxxxxxxx> 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
- References:
- Classes and access to outside variables
- From: Merlin
- Re: [PHP] Classes and access to outside variables
- From: "潘志彬"
- Classes and access to outside variables
- Prev by Date: Re: [PHP] Beginner Tutorials for using CLASSES in PHP4
- Next by Date: 500 Internal Server Error
- Previous by thread: Re: [PHP] Classes and access to outside variables
- Next by thread: Re: [PHP] Classes and access to outside variables
- Index(es):
Relevant Pages
|