RE: [PHP] PHP object communication
| From: | ad at m dot beecher dot net | Date: | Thu, 25 Oct 2001 10:55:40 +0000 |
| Subject: | RE: [PHP] PHP object communication | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-72245@lists.php.net to get a copy of this message | ||
Hi again Martín,
> Sorry for the TOO FAST RESPONCE! :-)
>
Itchy trigger finger, eh? :)
> $Core is one object, and Error and DB are properties of the object.
>
> Let me put it clearer. You have an Error object, and you now want
> to make a DB object, with the same properties of the Error object.
> Just extend it.
>
Ah, but I don't want them to have the same properties you see, I just want
to be able to access the properties. I'm probably trying to understand
something that simply isn't viable in OO, but I'd prefer to learn from my
mistakes than still have it niggling at the back of my mind. It basically
comes down to this:
How can I access this |
v
$Core->Error->Something
^
From this |
Consider the Car class:
<?php
class Brakes {
...
}
class Lights {
...
}
class Car {
var $brakes, $lights;
function Car() {
$this->brakes = new Brakes;
$this->lights = new Lights;
}
}
?>
I can't use 'extends' in this instance, because I don't want to mix up the
braking and the electrical system. However I do want to access the
electrical system if I hit the brake - to turn on the brake light. If I
*did* in fact use 'extends', I would use parent::lights->something() to
access the objects within Car. Is there some way of creating an equivalent
for sub-objects? Perhaps with references?
NOTE: An option I've tried would be to have Lights extend Car, however that
gives me problems with the constructor. When I initialise the extension, I'm
also initialising a new instance of Car. If I don't call the constructor, I
can't access the extended objects. If I do, I'm in a loop.
I'm not making sense, am I?
adam