WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. hubeRsen
    Member
    Posted 2 months 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.

    Cheers
    Stefan

    https://wordpress.org/plugins/wp-session-manager/

  2. hubeRsen
    Member
    Posted 2 months 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
    Member
    Plugin Author

    Posted 2 months ago #

    Strange indeed. Would you care to share your changes?

  4. hubeRsen
    Member
    Posted 2 months 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
    Member
    Posted 3 weeks 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.

Reply

You must log in to post.

About this Plugin

About this Topic