Re: first php 5 class

From: Date: Tue, 29 Jan 2008 20:32:29 +0000
Subject: Re: first php 5 class
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-268285@lists.php.net to get a copy of this message
nihilism machine schreef:
Ok, trying to write my first php5 class. This is my first project using all OOP PHP5.2.5. I want to create a config class, which is extended by a connection class, which is extended by a database class. Here is my config class, how am I looking?
dunno can't see you. but your class looks like crap, in fact it don't think it will even parse. have you tried running it?
<?php class dbconfig {
    public $connInfo = array();
    public $connInfo[$hostname] = 'internal-db.s23499.gridserver.com';
    public $connInfo[$username] = 'db23499';
    public $connInfo[$password] = 'ryvx4398';
    public $connInfo[$database] = 'db23499_donors';
the above is plain wrong. 1. you can't do multiple property definitions for a single [array] property 2. your storing hardcoded values in a class which is meant to be somewhat generic/reusable 3. you've just told the world your password/login/db credentials
    public __construct() {
        return $this->$connInfo;
    }
constructors aren't meant to return anything. besides you won't be able to retrieve the returned value. not too mention '$this->$connInfo' is the wrong syntax it should be: $this->connInfo I'd recommend some more research on basic class syntax.
} ?>


« previous php.general (#268285) next »