Re: Session variables are not stored when set in implicitly called constructor!??

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Adam wrote:
> Hallo everybody,
> hope I am writing to correct mailinglist(^_^*)...

Absolutely!

> I have troubles with sessions and descructor in php5. Can not set session
> variable in destructor when it's called implicitly. Do You know solution
> please?
> I think problem is that session is stored before imlicit object destruction
> *doh*
>
> example.php:
> <?php
> session_start();
> session_register("variable");

*Note* You don't need to use session_register() if you use $_SESSION.
In fact this probably isn't even doing what you think it is.  Using
$_SESSION indexes is the preferred way to go about using sessions.

>
> // singleton for request
> class Request {
>     function __destructor() {
>         $_SESSION["variable"] = "hallo";

The __destructor() method is supposed to be about killing the class
(Request).  It's probably bad practice to be changing $_SESSION vars
inside of there even if that $_SESSION var affects your class.  Here,
read this page and maybe it will make more sense to you:

http://php.net/manual/en/language.oop5.decon.php

Heck, look at the user contributed notes since one of them will directly
affect this idea of yours.

>     }
> }
>
> $req = Request::getInstance();
> $req->doSomeThink();
> echo "This should be hallo 2nd time: " . $_SESSION["variable"];    //
> unfortunatly this is not set
> echo " <a href='example.php'>Click and cry;-(</a>";
> // implicit desturctor call

If the reference count for $req is greater than 0 (i.e. there is a
Singleton) then __destruct won't be called.  And why should it be
called?  Because, again, __destruct is for cleaning up the class while
the object is getting destroyed.

> ?>
>
> Thank You very much...
> BR
> a3c


--
Teach a man to fish...

NEW? | http://www.catb.org/~esr/faqs/smart-questions.html
STFA | http://marc.theaimsgroup.com/?l=php-general&w=2
STFM | http://php.net/manual/en/index.php
STFW | http://www.google.com/search?q=php
LAZY |
http://mycroft.mozdev.org/download.html?name=PHP&submitform=Find+search+plugins

Attachment: signature.asc
Description: OpenPGP digital signature


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux