Serialize object from within
Posted
by
Maximus
on Stack Overflow
See other posts from Stack Overflow
or by Maximus
Published on 2013-10-19T09:47:48Z
Indexed on
2013/10/19
9:54 UTC
Read the original article
Hit count: 125
php
I have the class testClass
which has the method save
. This method saves object to a database. But it needs to serialize object before saving. How can I serialize object from within the class to do that?
class testClass {
private $prop = 777;
public function save() {
$serializedObject = serialize(self);
DB::insert('objects', array('id', 'object'))
->values(array(1, $serializedObject))
->execute();
}
}
serialize(self) obviously doesn't work.
© Stack Overflow or respective owner