Re: Class Help Extended
| From: | Torsten Roehr | Date: | Thu, 06 May 2004 09:02:14 +0000 |
| Subject: | Re: Class Help Extended | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-185502@lists.php.net to get a copy of this message | ||
"Richard Harb" <rharb@earthling.net> wrote in message
news:1946495175.20040506083618@earthling.net...
> More often than not it's a good thing to assign 'default' values to
> class variables like that.
>
> In this case though I've observed that common practice is to get the
> user/pass values from a config file and pass them along as variables
> when creating an instance of the class.
I'm defining things like DB access values as constants in my config file
rather than as global variables. This way I can make absolutely sure that
they are not accidently changed anywhere in my application. As constants are
globally available you don't need to pass them to every class method that is
using them.
<?php
class db_connection {
var $user = CONFIG_DB_USER;
var $pass = CONFIG_DB_PASSWORD;
var $db = CONFIG_DB_NAME;
var $host = CONFIG_DB_HOST;
var $connection;
....?>
Regards, Torsten
>
> Classes are most beneficial if you can take your class include file
> from one project to the next and just pass along different parameters
> and they work. Including user/pass would force you to edit/change
> those values on every project you use that class in.
>
> HTH
> Richard