Jump to content

prevent class destruction being called at the end of script


Recommended Posts

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

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...)

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.