Re: OOP Question in PHP

From: Date: Thu, 06 Jun 2002 00:00:21 +0000
Subject: Re: OOP Question in PHP
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-100831@lists.php.net to get a copy of this message
On Wed, Jun 05, 2002 at 10:32:39PM +0100, Henry Blackman wrote: > Do I create a new document and pass the primary key as it's a variable in > the > > $document = new Document(number); > > and have the constructor retrieve the appropriate data from MySQL and fill > the attribute variables. > > Or do I do something like: > > $document = new Document; > $document ->retrieve(number); > > Which is the best and most "valid" way of doing things. You could do both, and use whatever you find more appropriate at that moment: class Document { function Document($id='') { if($id) { $this->retrieve($id); } } function retrieve($id) { //do something } } BTW I get the feeling that you want retrieve() to output directly to the browser (echo/print...), IMHO you shouldn't do that at all but let retrieve() return a string/array/whatever. But that's up to you :) -- Daniel Tryba

« previous php.general (#100831) next »