_php_incomplete_class Object with serialization unserialize

Source: Internet
Author: User
__php_incomplete_class Object with serialization unserialize
I am dealing with a shopping cart class, because I have a special handling of the $_session, now need to put the shopping Cart object information into the $_session, directly processing object into my $_session inside is a failure, I have it serialized processing.

There is no problem with processing, but there is an error in calling the deserialized member function, __php_incomplete_class the problem of object.

The problem is very simple, that is, the instance of deserialization does not find the definition of the class, the processing method is very simple, the definition of the relevant class is placed in the session_start ();

Here is a way to add a deal of thought:

When a object is unserialized and its class definition doesn ' t exist
It becomes an instance of "__php_incomplete_class".

No problem ... however, what's annoying me is so you cannot treat it
Like a vanilla flavoured "stdClass", object and set its member variables.

Get_object_vars () would allow your 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, 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 (one) "Hello World", hooray!
?>


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

*one idea*
Could construct a StdClass instance, copy the proprties into it,
And then hack the resulting string, the object is serialized again.
Like ?>
However:this wouldn ' t work on session sleep!


Original: http://www.flymote.com/archiver/a-3078.html
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.