WP Session Manager
Can't update properties of stored objects (6 posts)

  1. Stefan Pasch
    Posted 1 year ago #

    Hi there

    i'm trying to update properties of a stored object (a stdClass). But they won't be updated inside the session.
    for example

    $s = WP_Session::get_instance();
    $s['obj'] = new stdClass();
    $s['obj']->test = 'yep';

    will correctly store the stdClass into the session. But when i later wan't to change "test" or add a new property to "obj", it will be lost upon the next reload.

    What's wrong here? Thank you for any help.



  2. Stefan Pasch
    Posted 1 year ago #

    Ok, it seems the dirty flag doesn't get updated when properties of an object are changed. I've solved this now by adding a changed flag by myself as a root array element, which will cause the dirty flag to get updated.

    Strange anyway.

  3. Eric Mann
    Plugin Author

    Posted 1 year ago #

    Strange indeed. Would you care to share your changes?

  4. Stefan Pasch
    Posted 1 year ago #

    Hi Eric

    i don't really have changes. The bug still exists. I just have a simple workaround.

    Whenever i change a property inside a object in the session, i'll update a changed flag on the session array too, so the "dirty" flag gets updated and the session data will be rewritten.

    This will work

    $s = WP_Session::get_instance();
    $s['obj']->test = 'nope';
    $s['myupdateflag'] = microtime();

    This won't work

    $s = WP_Session::get_instance();
    $s['obj']->test = 'nope';
  5. indextwo
    Posted 1 year ago #

    Thankyou, @hubeRsen - I was suffering with exactly the same issue: trying to update a WP_Session object that already existed just wasn't working. I added a dirty flag each time the session data was appended to (via ajax) and boom - all my values are stored. Works like a charm.

  6. Studio dub
    Posted 9 months ago #

    Just verifying that this 'dirty' fix is working for me as well. Thanks for sharing.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WP Session Manager
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic