开发者

Removing objects form serialize data

I am trying to integrate two PHP scripts (app1, app2) and I am trying to get session data from app开发者_运维问答1 in app2.

The problem is when I am trying to unserialize the session data from app1 I am getting a small ton of errors because PHP is trying to find the __wakeup() function for each of the objects.

I can't use the unserialize_callback_func fix because app2 use it so its already set and can't be changed.

I don't need any data in the objects, is there some-way I can just remove the objects so they wont cause any problems?


You could be able to set the unserialize_callback_func to your own and change it back afterwards.

$oldCallback = ini_get("unserialize_callback_func");

ini_set("unserialize_callback_func", "myNewCallback");
yourUnserialize();

ini_set("unserialize_callback_func", $oldCallback);

Also if the objects don't exists in App2 you could also use autoloading to create the classes on the fly (without any methods), but that seems more hackisch

Update for Scotts comment:

This is getting really hackisch but it might to the job:

<?php
$serialized_object='O:1:"a":1:{s:5:"value";s:3:"100";}';

ini_set('unserialize_callback_func', 'mycallback');
function mycallback($classname)
{
    eval("class $classname {}");
}

var_dump(unserialize($serialized_object));
?>
// Prints:
object(a)#1 (1) {
  ["value"]=>
  string(3) "100"
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜