Basically, I'm trying to make an object a reference another object of the same class - from within the method. It would be ideal if the following worked:
$this = new self;
But you cannot reassign $thisin php.
Of course, I know, I can return another object from the method and use it, so please do not advise this. The question arises:
How can I do $thisto be a clone of another object of the same class?
or more specifically
I want the object to return to a specific state that was previously saved.
EDIT : some examples where this might be useful.
Let's say you have an Url object that takes a controller, an action, and more. You are going to get a lot of links with the same, say, controller and action, but other properties will be different. I create an instance of the object using the general parameters, call the method to save its state, which it returns after the link is displayed (IOW after the __toString method).
$defaultPath = Url::factory('controller','action1')->extraParams('status',0)->save();
echo $defaultPath->action('action2');
echo $defaultPath->extraParams('status',2);
Another use: I have a CRUD table, and I have to configure each column as an object that I pass to the main table object. After passing the column, I run the reset method on the column, so I can have the following code:
$column->field = 'layouts_id';
$column->value = $layoutId;
$dbInput->addColumn($column);
$column->field = 'pages_id';
$column->value = $pagesId;
$dbInput->addColumn($column);
In both situations, I save a lot of code and confusion, right?