Re: Classes and access to outside variables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux