If you are passing the serialized object from one script to the next, then it is doable.
What I understand is that you want to generate and object and then use it with a different class definition to use variations of the methods, etc.
In PHP objects only keep a pointer to the name of the method, not to the method body, therefore something like the following 2 scripts:
[obj1.php]
<?php
class foo {
var $msg;
function p() {
$this->msg = "I am an object\n";
echo $this->msg;
}
}
$o1 = new foo;
$o1->p();
$ser = serialize($o1);
$fp = fopen("ser.txt", "w");
fwrite($fp,$ser);
fclose($fp);
?>
[obj2.php]
<?php
// different foo class
class foo {
var $msg;
var $when = " right now\n";
function p() {
$this->msg = " 5 beers";
echo "fooled you!, give me".$this->msg.$this->when;
}
}
$ser = implode("",file("ser.txt"));
$o2 = unserialize($ser);
$o2->p();
?>
Should give when run:
% php -q obj1.php
I am an object
% php -q obj2.php
fooled you!, give me 5 beers right now
HTH