Re: first php class take 2

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

 



On Jan 29, 2008 3:36 PM, Jochem Maas <jochem@xxxxxxxxxxxxx> wrote:
> nihilism machine schreef:
> > How does this look now?
>
> just as bad as before. you haven't even tried to run the code have you?
>
>
> >
> > <?php
> >
> > class dbconfig {
> >     public $connInfo = array();
> >     public $connInfo[$hostname] = 'host.com';
> >     public $connInfo[$username] = 'dbuser';
> >     public $connInfo[$password] = 'dbpass';
> >     public $connInfo[$database] = 'mydbname';
> >
> >     public __construct() {
> >         return $this->$connInfo;
> >     }
> > }
> >
> > ?>
> >
> > <?php
> >
> > include_once("dbconfig.class.php");
> >
> > class dbconn extends dbconfig {
> >
> >     public $DB;
> >
> >     public __constructor(){
> >         $this->$connInfo = new dbconfig();
> >         $username =
> >         $hostname =
> >         $password =
> >         $database =
> >         $DB = new
> > PDO("mysql:host=$connInfo[$hostname];dbname=$connInfo[$database]",
> > $connInfo[$username], $connInfo[$password]);
> >         return $DB;
> >     }
> > }
> >
> > ?>
> >
>

And it's not really good OO, either. Saying that dbconn extends
dbconfig is saying that "a database connection IS-A database
configuration". It isn't. You might say that "a database connection
HAS-A database configuration." Actually, your code says that "a
database connection IS-A database configuration that HAS-A database
configuration" since dbconfig is both a member property and a parent
class of dbconn. And, as pointed out on your other thread, the
dbconfig constructor should not even have a return statement.

I'm definitely no OO expert, but it looks like you are trying to use
OOP simply because you can, even though you don't seem to understand
how objects can/should relate to one another.

Andrew

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[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