note 110553 deleted from function.unserialize by aharvey
| From: | aharvey@php.net | Date: | Tue, 06 Nov 2012 08:46:02 +0000 |
| Subject: | note 110553 deleted from function.unserialize by aharvey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-191781@lists.php.net to get a copy of this message | ||
Note Submitter: team at researchbib dot com
----
When you meet '__PHP_Incomplete_Class_Name' by using unserialize , please confirm whether
you have included the class file in serialized contents before you use unserialize function.
For example:
Include class
<?php
/*SimpleClass.php*/
class SimpleClass{
var $key;
function SimpleClass(){
}
function __set($name,$value){
$this->key[$name] = $value;
}
function __get($name){
return $this->key[$key];
}
}
?>
Write file
<?php
/*Store.php
*/
require_once './SimpleClass.php';
$SimpleClass = new SimpleClass;
$SimpleClass->keywords = 'Google';
@file_put_contents('./aaa.txt', serialize($SimpleClass));
?>
Wrong Read file
<?php
/*Read.php
*/
$SimpleClass = unserialize(file_get_contents('./aaa.txt'));
print_r($SimpleClass);
?>
Wrong Output
__PHP_Incomplete_Class Object
(
[__PHP_Incomplete_Class_Name] => SimpleClass
[key] => Array
(
[keywords] => Google
)
)
In order to resolve this problem, you should include the class file in serialized contents before
you use unserialize function.
Correct Read File
<?php
/*Read.php
*/
require_once './SimpleClass.php';
$SimpleClass = unserialize(file_get_contents('./aaa.txt'));
print_r($SimpleClass);
?>
Correct Output
SimpleClass Object
(
[key] => Array
(
[keywords] => Google
)
)