I have a method in my class that accepts an object by reference. It decorates that object to extend the functionality.
basically...
public function addObject( &$object ) {
$object = $this->decorate( $object );
}
I'm trying to write a convenience method addObjects() but it's not changing $object
This does not work...
public function addObjects( array &$objects ) {
foreach( $objects as $object ) {
$this->addObject( $object );
}
}
I've tried a bunch of other routes but none have worked. I'm sure there's a way to do this, but it's escaping me. Maybe i've been staring at my computer too long.
Here's is a live example
Update
It seems there's no way other than to pass references when creating the array of objects
$objects = array( &$object1, $object2 ); //object1 will be decorated, object2 will not
$thing->addObjects( $objects );
$objects = NULLin the function, and thenvar_dump()after the function has returned?