nekokumi Posted January 15, 2008 Share Posted January 15, 2008 hi again i have question again. please see the simplified code, my question and explanation is in the comment in code. if ($_POST['test']) { if (isset($_SESSION['a'])) { $a= $_SESSION['a']; $a->say($_POST['test']); // say() function doesn't work as expected because $a destructor already being called in end of script, so some needed variable are freed. // i would like the $a destructor called here unset($_SESSION['a']); } } else { $a= new test(); $a->get_something_and_display_it(); $_SESSION['a'] = $a; echo "<form action='test_create2.php' method='post'> <input type='text' name='test'> <input type='submit' value='Enter text'> </form>"; // $a test() class destructor is called here, but i'm planning to use $a variable method after the page posted // and that's why i saved the $a variable into a session. // i would like to prevent $a destructor being called here. } there is a way i think, moving the destructor into a method like free(); but is that the only way / correct way? i need your help and suggestion guys thank you Quote Link to comment https://forums.phpfreaks.com/topic/86145-prevent-class-destruction-being-called-at-the-end-of-script/ Share on other sites More sharing options...
nekokumi Posted January 15, 2008 Author Share Posted January 15, 2008 update: i try moving the destructor content into free() method also doesn't work because the whole class being destructed at the end of script. Quote Link to comment https://forums.phpfreaks.com/topic/86145-prevent-class-destruction-being-called-at-the-end-of-script/#findComment-439938 Share on other sites More sharing options...
PFMaBiSmAd Posted January 15, 2008 Share Posted January 15, 2008 Web servers and any server side scripting languages used on them are stateless. All resources that a php script uses are destroyed at the end of code execution on a page. If you want to carry information between pages it must be specifically stored or passed between pages (database, flat-file database, session data file, parameters on the end of the url, cookies...) Quote Link to comment https://forums.phpfreaks.com/topic/86145-prevent-class-destruction-being-called-at-the-end-of-script/#findComment-439945 Share on other sites More sharing options...
nekokumi Posted January 15, 2008 Author Share Posted January 15, 2008 Web servers and any server side scripting languages used on them are stateless. All resources that a php script uses are destroyed at the end of code execution on a page. If you want to carry information between pages it must be specifically stored or passed between pages (database, flat-file database, session data file, parameters on the end of the url, cookies...) Thanks for your reply. Yes, that's why i saved it the variable into a session variable. here is another example what i am doing to be more clear: page: a.php - $a = new test(); - save $a into session['a'] (page a.php ends, $a destructor are being called) page: b.php - $a = session['a']; - $a->some_method(); // Failed, because some of the variable inside test() class already freed, when page a.php ends. Quote Link to comment https://forums.phpfreaks.com/topic/86145-prevent-class-destruction-being-called-at-the-end-of-script/#findComment-439960 Share on other sites More sharing options...
PFMaBiSmAd Posted January 15, 2008 Share Posted January 15, 2008 Make sure your class definition exists in the script before the session_start() on the second page. Quote Link to comment https://forums.phpfreaks.com/topic/86145-prevent-class-destruction-being-called-at-the-end-of-script/#findComment-439987 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.