For example:
Include class
/*SimpleClass.php*/Write file
class SimpleClass{
var $key;
function SimpleClass(){
}
function __set($name,$value){
$this->key[$name] = $value;
}
function __get($name){
return $this->key[$key];
}
}
?>
/*Store.php
*/
require_once './SimpleClass.php';
$SimpleClass = new SimpleClass;
$SimpleClass->keywords = 'Google';
@file_put_contents('./aaa.txt', serialize($SimpleClass));
?>
Wrong Read file
/*Read.php
*/
$SimpleClass = unserialize(file_get_contents('./aaa.txt'));
print_r($SimpleClass);
?>
Wrong Output
__PHP_Incomplete_Class ObjectIn order to resolve this problem, you have to include the class file in serialized contents before you use unserialize function.
(
[__PHP_Incomplete_Class_Name] => SimpleClass
[key] => Array
(
[keywords] => Google
)
)
Correct Read File
/*Read.php
*/
require_once './SimpleClass.php';
$SimpleClass = unserialize(file_get_contents('./aaa.txt'));
print_r($SimpleClass);
?>
Correct Output
SimpleClass Object
(
[key] => Array
(
[keywords] => Google
)
)
Thank you for an very good responds!
ReplyDelete