2

I have been going crazy over this piece of code and narrowed it down to the unset function. When I call unset on the session variable, PHP doesn't execute anything beyond that point. Can someone please help?

public static function print_session_notification() {

    if( isset( $_SESSION['notification'] )) {
        $session_notification = $_SESSION['notification'];

        $output = '<div class="error">';
        $output .= $_SESSION['notification'];
        $output .= '</div>';

        unset( $_SESSION['notification'] );

        return $output;
    }
}

I call print notification::print_session_notification(); from a header include. The header include is called by a function. The $notification object is global in the function that calls the header file.

Randy Gonzalez
  • 445
  • 5
  • 17
  • There's nothing wrong with the code you posted, and it won't reproduce your error. Try reproducing your error with the smallest amount of code possible. We can't help you with what you've posted. – user229044 Oct 27 '11 at 20:24
  • Do you have register_globals being 'ON'? http://www.php.net/manual/en/function.unset.php#40539 possibly related: http://stackoverflow.com/questions/1025300/problem-unsetting-a-session-variable – Phill Pafford Oct 27 '11 at 20:33
  • We'll need to see the code or function which calls `print_session_notification()`, at the very least. – Michael Berkowski Oct 27 '11 at 20:33
  • Why are localizing the session value to $session_notification, but not using it? Seems like you can just get rid of that line. – Mike Purcell Oct 27 '11 at 20:39
  • Sorry Guys I forgot to mention that I call print notification::print_session_notification(); from a header include. The header include is called by a function. – Randy Gonzalez Oct 27 '11 at 21:43

2 Answers2

0

I fixed the issue by adding a method to the construct and assigning the session values to public properties. Thanks for your help guys!!!

Randy Gonzalez
  • 445
  • 5
  • 17
-1

Please make sure that you set session_start() function on you header and set register_globals to "ON"

For more information read the comments on http://www.php.net/manual/en/function.unset.php

Leysam Rosario
  • 379
  • 2
  • 11