note 113994 added to function.serialize
| From: | NanheKumar | Date: | Fri, 27 Dec 2013 05:57:39 +0000 |
| Subject: | note 113994 added to function.serialize | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-198035@lists.php.net to get a copy of this message | ||
Note : You cannot save the state of a static variable by serializing.
<?php
/*
* student.class.php
*/
class Student {
public $name;
private $roll;
protected $age;
static $class;
public function __construct() {
$this->name = "Nanhe Kumar";
$this->roll = 1;
$this->age = 16;
Student::$class = "10+2";
}
}
?>
<?php
/**
* serialize.php
*/
include_once("student.class.php");
//Serialize
$so = new Student();
$serialized = serialize($so);
file_put_contents("test.txt", $serialized);
echo $serialized; //O:7:"Student":3:{s:4:"name";s:11:"Nanhe
Kumar";s:13:"Studentroll";i:1;s:6:"*age";i:16;}
?>
<?php
/**
* unserialize.php
*/
include_once("student.class.php");
$content = file_get_contents("test.txt");
$unserialized = unserialize($content);
print_r($unserialized);//Student Object ( [name] => Nanhe Kumar [roll:Student:private] => 1
[age:protected] => 16 )
?>
----
Server IP: 72.52.91.14
Probable Submitter: 72.52.91.14
----
Manual Page -- http://php.net/manual/en/function.serialize.php
Edit -- https://master.php.net/note/edit/113994
Del: integrated -- https://master.php.net/note/delete/113994/integrated
Del: useless -- https://master.php.net/note/delete/113994/useless
Del: bad code -- https://master.php.net/note/delete/113994/bad+code
Del: spam -- https://master.php.net/note/delete/113994/spam
Del: non-english -- https://master.php.net/note/delete/113994/non-english
Del: in docs -- https://master.php.net/note/delete/113994/in+docs
Del: other reasons-- https://master.php.net/note/delete/113994
Reject -- https://master.php.net/note/reject/113994
Search -- https://master.php.net/manage/user-notes.php