The function serialize () returns a string containing a byte-stream representation of any value that can be stored in PHP. Using serialize to save an object will save all variables in an object.
Syntax for serialization
<?php
// define class with variables and methods
class className {
public $var = "value here...";
public function func() {
// code here...
}
}
// call class
$class = new className();
$ser = serialize($class);
?>
Example with object serialization
<?php
// define class with variables and methods
class className {
public $var = "variable";
public function func() {
echo $this -> $var;
}
}
// call class
$class = new className();
$ser = serialize($class); // store somewhere
?>
Comments
No comments have been made yet.
Please login to leave a comment. Login now