__PHP_Incomplete_Class hacks

__PHP_Incomplete_Class hacks

am 23.02.2006 17:44:35 von Fabian Hore

When an object is unserialized and its class definition doesn't exist
it becomes an instance of "__PHP_Incomplete_Class".

no problem... however, what is annoying me is that you cannot treat it
like a vanilla flavoured "stdClass" object and set its member variables.

get_object_vars() will allow you to get a property, but you cannot set any!
try my example:

// force a __PHP_Incomplete_Class object
$sleepstring = 'O:12:"missingclass":1:{s:5:"myvar";s:11:"hello world";}';
$Obj = unserialize($sleepstring);

// test that its broke!
$isbroken = is_a($Obj, '__PHP_Incomplete_Class');
var_dump($isbroken); // bool(true)

// test properties
var_dump( $Obj->myvar ); // NULL, and raises E_NOTICE
$vars = get_object_vars($Obj);
var_dump( $vars['myvar'] ); // string(11) "hello world", hooray!
?>


Anyone know a hack/workaround to set a value in the object?

*one idea*
You could construct a stdClass instance, copy the proprties into it,
and then hack the resulting string when the object is serialized again.
like: ?>
however: this wouldn't work on session sleep!

Re: __PHP_Incomplete_Class hacks

am 24.02.2006 22:34:21 von Janwillem Borleffs

Fabian Hore wrote:
> Anyone know a hack/workaround to set a value in the object?
>

Here's an idea:

ini_set('unserialize_callback_func', 'mycallback');
function mycallback($c) {
eval("class $c {}");
}
// Rest of your code


JW

Re: __PHP_Incomplete_Class hacks

am 27.02.2006 20:10:05 von Fabian Hore

I was not aware of that ini setting - splendid!


"Janwillem Borleffs" wrote in message
news:43ff7bdc$0$43165$dbd45001@news.euronet.nl...
> Fabian Hore wrote:
>> Anyone know a hack/workaround to set a value in the object?
>>
>
> Here's an idea:
>
> ini_set('unserialize_callback_func', 'mycallback');
> function mycallback($c) {
> eval("class $c {}");
> }
> // Rest of your code
>
>
> JW
>