views:

55

answers:

1

I am trying to integrate two PHP scripts (app1, app2) and I am trying to get session data from app1 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?

+2  A: 

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"
}
edorian
The objects don't exists in App2, I was wondering if I could change the unserialize_callback_func but I haven't been able to create the classes dynamically.
Scott
I've updated my answer to show off a little working example, even so eval() isn't really nice it's an easy way to create those classes on the fly. Hope it works out for you
edorian
A little risky but it should work, I still think that there should be a way to remove them or just not load them when using unserialize.
Scott
Agreed, but i didn't want to go into string parsing )
edorian