Here is another possible solution for migrating code to php 5 when using $this = 'something' reassignments. In my case, I had several classes with methods that were self-instantiating with static calls. I was able to simply use a different variable: I changed $this to $_this and it worked the same because I copied an instance of the original object by reference using an instantiation factory method:
class DB {
function &getInstance()
{
static $instance = null;
if ($instance === null) {
$instance = new DB();
}
return $instance;
}
...
In every method needing access to this object I assigned it to a temporary variable by reference:
function doSomething ()
{
$_this =& DB::getInstance();
$_this->doSomethingElse();
$_this->param['id'] = 123;
}
Which allows method calls or saving data back to the original object.
I originally created classes like this so I didn't need to keep track of instantiations or global objects. I could just call DB::doSomething() and the object is created dynamically or referenced from an already existing object.