• Resolved trevorwood

    (@trevorwood)


    I’m probably doing something very stupid here but I can’t figure out what.

    I have a page with a number of PHP functions in

    when I set a $wp_session variable in a function, it doesn’t appear to be being returned to the parent

    here’s a very simplified version of what is happening

    $wp_session = WP_Session::get_instance();

    callfunction ();

    function callfunction ()
    {
    $wp_session = WP_Session::get_instance();
    $wp_session = [‘test’] = ‘test’;

    — then we display a form with a submit button, this calls the same page
    }

    when I print_r $wp_session after setting ‘test’, test shows. However, when I do the same on re-entering the page it doesn’t

    been bugging me for a couple of days now 🙁

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Eric Mann

    (@ericmann)

    That should be

    $wp_session['test'] = 'test';

    Your extra = in the code will force an assignment, overwriting the $wp_session variable with something else.

    Thread Starter trevorwood

    (@trevorwood)

    sorry – the initial = was a mis-type. I do have
    $wp_session[‘test’] = ‘test’;

    on further investigation, it is nothing to do with the form, it is something to do with the session variable being set in a function.

    I’ve got a work around by returning the value I want to put into the session variable from the function and then settign that into the session variable

    e.g
    $val = callfunction ();
    $wp_session[‘test’] = $val

    function callfunction ()
    {
    some code that sets $val
    return $val;
    }

    It’s horrible, but at least I can carry the session variables around now

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Cariables set inside function are not being returned to parent’ is closed to new replies.