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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Locked
pivdet
Forum Newbie
Posts: 3
Joined: Sun Nov 02, 2008 9:24 pm

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

Post 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?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

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

Post by John Cartwright »

Duplicate. Locked.
Locked