I'm compositing a class based on other classes. The component classes 
are (this is for a transportation application) fuel and vehicle. The 
container class is mode (as in mode of transit: rail, bus, etc.). There 
can be several vehicles and fuels for each mode (many to one). I want 
to be able to accomplish something like this:

$bus = new mode();
$diesel = new fuel($bus);
$ethanol = new fuel($bus);
$class_a_bus = new vehicle($bus);
$articulated_bus = new vehicle($bus);

In other words, register the fuels and vehicles with the mode object in 
such a way that I don't have to make them members of said object; in 
further other words, instead of doing it something like:

$bus = new mode();
$diesel = new fuel();

Is there a way I can then reference the components of the mode object 
without having to know the names I picked for the variables; without 
having to do something like:

$diesel = new fuel();
$bus->addFuel($diesel, 'diesel'); <-- a handle to reference the 
globally scoped variable

One kludgy way would be to foreach() the $GLOBALS in a method of the 
mode class, checking for is_a('fuel'). One of my rules of thumb is to 
reduce use of the $GLOBALS. Would a more elegant solution be related to 
PHP's reference counting? I apologize if this is a confusing-as-hell 
post. I would be more than happy to clarify a point...


Center for Neighborhood Technology
Chicago, IL USA

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to