I have a base class of FileCopier that is composed with two “has-a” associations to Resource Source and Resource Destination.
After construction, three properties exist in FileCopier:
- Source (instance of Resource)
- Destination (instance of Resource)
- Config (array of configuration stuff for this FileCopier)
All of the examples I find on this issue are regarding children by extension rather than children by composition.
My question is: is there any way for the Resource instance to access it’s parent’s “Config”?
Or, must I pass a reference to the parent to it’s associated children, say, via the constructor?
If I understand well you have:
And you want to access $conf from $source and $destination?
There is no parent or other magic word to access this $conf from the two other variables.
Your best bet would be to add a function to Resource which will set a local reference to Config:
Or if config is set at some other point r could change or if for whatever other reason you want to access the latest $conf from your resources you can pass a ref to FileCopier instead:
Then all you have to do is to call your setter before using $source and $destination. Probably in the FileCopier:
Hope this helps.