[PHP] RE: PHP object communication

2001-10-29 Thread ad

Sorry, it was Tim that suggested that what I required wasn't really OO. My
apologies Tim, and thanks for your emails.

adam



Adam Beecher - CEO  Core Geek - ieWebs™

e  ...  [EMAIL PROTECTED]
w  ...  http://www.iewebs.com
m  ...  Box 81, Eglinton St, Cork, Ireland



 -Original Message-
 From: Tim Ward [mailto:[EMAIL PROTECTED]]
 Sent: 25 October 2001 12.04
 To: [EMAIL PROTECTED]; Tim Ward; [EMAIL PROTECTED]
 Subject: RE: PHP object communication


 see below for comments

   Tim Ward
   Senior Systems Engineer

 Please refer to the following disclaimer in respect of this message:
 http://www.stivesdirect.com/e-mail-disclaimer.html


  -Original Message-
  From:   [EMAIL PROTECTED] [SMTP:[EMAIL PROTECTED]]
  Sent:   Thursday, October 25, 2001 11:56 AM
  To: Tim Ward; [EMAIL PROTECTED]
  Subject:RE: PHP object communication
 
  Hi Tim,
 
   If you want access to error functions within the db class it
 must either
   extend the error class or have an error object within it. Either ...
  
  I'll go for the latter, because extends isn't appropriate in this case:
   [Tim Ward]  I think I would use the second option in your case as
 well, but always consider inheritance, it's beter where it is appropriate

   Class DB
   { var $error;
   ...
 function DB() // constructor
 {   ...
 $this-error = new Error();
 }
   ...
   }
  
   Class Core
   { var $db;
 var error;
  
 function Core() // constructor
 {   ...
 $this-db = new DB();
 $this-error = new Error();
 ...
 }
   }
 at the end of the day, both these are ways of getting around the
   lack of multiple inheritance
  
 
  In this case, don't I have a completely different error object in
  $Core-db?
 [Tim Ward]  Yes, which is exactly what you want.

 the classes DB and Core both need to handle their own errors.
 What you don't
 want to do is handle errors in DB within an instance of Core. That would
 mean DB cannot cannot function except as part of Core. Remember  .. there
 are 2 O's in OOP, the second one is important. Each class should be
 complete. if you try to get DB to use error functions defined (or
 inherited
 by) in Core you are effectively trying to get a parent to inherit from a
 child.
 
  adam



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] RE: PHP object communication

2001-10-25 Thread Tim Ward

If you want access to error functions within the db class it must either
extend the error class or have an error object within it. Either ...

Class DB extends Error
{   ...
}

Class Core extends DB
{   ...
}

or 

Class DB
{   var $error;
...
function DB() // constructor
{   ...
$this-error = new Error();
}
...
}

Class Core
{   var $db;
var error;

function Core() // constructor
{   ...
$this-db = new DB();
$this-error = new Error();
...
}
}
at the end of the day, both these are ways of getting around the
lack of multiple inheritance

Tim Ward

--
From:  [EMAIL PROTECTED] [SMTP:[EMAIL PROTECTED]]
Sent:  24 October 2001 22:45
To:  [EMAIL PROTECTED]
Subject:  PHP object communication

Not coming from a programming background, I'm going to have
difficulty
explaining this one... :)

I would like to handle an entire application through one object,
which in
turn contains objects. I only recently got classes though, and I
don't
fully understand if what I want to do is possible, or if I'm going
about it
the wrong way. Consider:

?php

// All of these will be in separate files.
// The first two are separated simply because
// I want to keep my include files small.

class Config {
// Base config class.
// Just contains data.
}

class Core extends Config {
// Base application class.
// Just contains methods.
}

class Error {
// Error handler.
}

class DB {
// Database handler.
}

?

Tying the first two together is no problem, I can just extend the
Config
class. However I would like to incorporate the third and fourth as
objects
inside the main object:

?

// In fact these would be instantiated (is that the
// right word?) inside the Core class.

$Core= new Core;
$Core-Error = new Error;
$Core-DB= new DB

?

This is fine when working in the main application, or in the $Core
object,
but where I get stuck is with communication between the $Core-Error
and
$Core-DB objects. Say for example that within the DB class I
encountered an
error, and wanted to talk to the Error object - I /could/ do this:

?

class DB {

var $Error;

function DB() {
global $Core;
$this-Error = $Core-Error;
}

}

?

But if I extend the application later and add a bunch of new
classes, it
means I have to do the same for each object I add. I get the
impression that
I might be able to do this with references, but I can't get a handle
on them
for the life of me. Can someone explain?

Sorry for the lengthy post.

Thanks,
adam


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] RE: PHP object communication

2001-10-25 Thread ad

Hi Tim,

 If you want access to error functions within the db class it must either
 extend the error class or have an error object within it. Either ...

I'll go for the latter, because extends isn't appropriate in this case:

 Class DB
 { var $error;
 ...
   function DB() // constructor
   {   ...
   $this-error = new Error();
   }
 ...
 }

 Class Core
 { var $db;
   var error;

   function Core() // constructor
   {   ...
   $this-db = new DB();
   $this-error = new Error();
   ...
   }
 }
   at the end of the day, both these are ways of getting around the
 lack of multiple inheritance


In this case, don't I have a completely different error object in $Core-db?

adam


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] RE: PHP object communication

2001-10-25 Thread Tim Ward

see below for comments

Tim Ward
Senior Systems Engineer

Please refer to the following disclaimer in respect of this message:
http://www.stivesdirect.com/e-mail-disclaimer.html


 -Original Message-
 From: [EMAIL PROTECTED] [SMTP:[EMAIL PROTECTED]]
 Sent: Thursday, October 25, 2001 11:56 AM
 To:   Tim Ward; [EMAIL PROTECTED]
 Subject:  RE: PHP object communication
 
 Hi Tim,
 
  If you want access to error functions within the db class it must either
  extend the error class or have an error object within it. Either ...
 
 I'll go for the latter, because extends isn't appropriate in this case:
[Tim Ward]  I think I would use the second option in your case as
well, but always consider inheritance, it's beter where it is appropriate

  Class DB
  {   var $error;
  ...
  function DB() // constructor
  {   ...
  $this-error = new Error();
  }
  ...
  }
 
  Class Core
  {   var $db;
  var error;
 
  function Core() // constructor
  {   ...
  $this-db = new DB();
  $this-error = new Error();
  ...
  }
  }
  at the end of the day, both these are ways of getting around the
  lack of multiple inheritance
 
 
 In this case, don't I have a completely different error object in
 $Core-db?
[Tim Ward]  Yes, which is exactly what you want.

the classes DB and Core both need to handle their own errors. What you don't
want to do is handle errors in DB within an instance of Core. That would
mean DB cannot cannot function except as part of Core. Remember  .. there
are 2 O's in OOP, the second one is important. Each class should be
complete. if you try to get DB to use error functions defined (or inherited
by) in Core you are effectively trying to get a parent to inherit from a
child.
  
 adam

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]