The scenario: fetch an email template from the database, and loop through a list of recipients, personalising the email for each.
My email template is returned as a
Another more generic and powerful solution: MyCLabs\DeepCopy.
It helps creating deep copy without having to overload __clone
(which can be a lot of work if you have a lot of different objects).
You could add a __clone() method to your email class. Which is automatically called when an instance of this class is cloned via clone(). In this method you can then manually add the template.
Example:
class email {
__clone() {
$this->template = new template();
}
}
.
unserialize(serialize($object)); // would be another solution...