NYCPHP Meetup

NYPHP.org

[nycphp-talk] Setting up PHP 4 OOP to work in PHP 5 environment

Randal Rust rrust at r2communications.com
Thu Feb 24 10:38:12 EST 2005


csnyder wrote:

> A singleton is a class which returns an instance of some object. 

ok. thanks for the explanation. fwiw, i am starting to read up on OOP, 
starting with adam's php 5 book.

> If you have a lot of classes that instantiate the same objects over
> and over on construction, you might consider something like:
> 
> class Employer {
>   function Employer() {
>     global $DB;
>     $this->db =& $DB;
>   }
> }
> 
> $DB = new DB;
> $employer = new Employer;

you are exactly right. but i found that my approach....

 >        function Employer(){
 >                 $this->db =& new DB;
 >                 $this->display =& new Display;
 >                 $this->validator =& new Validator;
 >                 $this->db=$this->db->conn;
 >                 }

...allowed me to only have these lines in my php page...

$employer = new Employer
$db=$employer->db;

as far as i knew, this just allowed me to put less code in my pages.

-- 
Randal Rust

R.Squared Communications
http://www.r2communications.com
Digital Design for Bricks-and-Mortar Businesses




More information about the talk mailing list