Page 1 of 1

Is it possible to unserialize a object with a func in it?

Posted: Sun Sep 20, 2009 9:11 pm
by pivdet
Hi, all
I wrote a simple php file like this:

Code: Select all

 
class A {
  function A($data) {
    $this->data = $data;
  }
 
  function printData() {
    print 'A thinks A data is ' . $this->data . "\n";
  }
}
 
 
$a = new A("origAdata");
print '<pre>';
$a->printData();
 
$serA = serialize($a);
echo "<br>" . $serA . "<br>";
 
Simply, it works like
O:1:"A":1:{s:4:"data";s:9:"origAdata";}
However, I wrote a second file:

Code: Select all

$newA = unserialize('O:1:"A":1:{s:4:"data";s:9:"origAdata";}');
$newA->data = 'newAdata';
$newA->printData();
 
This time it fails, I am wondering if I can unserialize a object with a func in it?

Re: Is it possible to unserialize a object with a func in it?

Posted: Sun Sep 20, 2009 11:20 pm
by John Cartwright
Duplicate. Locked.