PEAR coding style!
| From: | David Tandberg-Johansen | Date: | Fri, 14 Feb 2003 12:11:05 +0000 |
| Subject: | PEAR coding style! | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-3761@lists.php.net to get a copy of this message | ||
Hi!
I am trying to understand how to build aplication based on the PEAR lib.
I build the aplication in this type hieraki:
class.Master.php (Here I make the PEAR/PEAR DB include)
|- class.level0.php (This class are the one I include in the www page)
|-class.level1A.php
| |-class.level2A.php
|-class.level1B.php
|-class.level1C.php
In class.Master.php I require the PEAR class and the DB class. In the Master
constructor i do as follow:
function Master()
{
$this->PEAR();
//here I have an function that makes the DSN
$this->db = DB::connect($this->makeDSN());
if (DB::isError($this->db)){
die("A fatale error have accoured");
}
}
In the class.level0.php i require the the class.Master.php file and in the
constructor i do:
function level0()
{
$this->Master();
}
to inherit the atributes and objects from the Master class
But as i tried to show in my filetree i have some classes under the
class.level0.php file/class, and some of them uses an DB connection. I have
tried to do for ex in class.level1A.php like this:
function level1A()
{
$this->level0();
}
I got an error that says it can't re initiate the DB class again.
So I do as follow in the class.level0.php:
function level0()
{
$this->Master();
$this->initSubClasses()
}
function initSubClasses()
{
$this->level1A =& new level1A($this->db)
//this I do for all the sub classes under level0
}
And in for ex the constructor of class.level1A.php i do:
function level1A($db)
{
$this->db = $db;
}
But I have experienced some times that the sub classes doesn't inherit the
db object correctly.
So, do I do it the right way, or is there an better way to do it.
Thanks
David