Reply to Re: [PHP] Re: Session variables are not stored when set in implicitly calledconstructor!??

Your name:

Reply:


Posted by Jochem Maas on 04/21/05 10:37

Jason Barnett wrote:
> Adam wrote:
>
>>Hallo again,
>>thank You for Your response.
>>
>>
>>
>>>>// 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
>>
>>
>>i agree that in *most* cases destructor should only clean up after object.
>>unfortunatly for "request" class there are few requirements:
>>1) must allow immidiate use w/o any explicit initialization or finalizaion.
>>e.g. at any file You can use only Request::getInstance()->isRefresh() /**
>>test if this request was caused by browser refresh */. this should be one
>>and only line (except for inclusion of request.php oc) referencing request
>>class -- no explicit call to Request::saveToSession() or anything ugly and
>>potentialy disastrous like that.
>
>
> Well ok, but why can't you just have saveToSession() in the conditional
> block?
>
> <?php
>
> $_SESSION['Request'] = Request::getInstance();
>

look $_SESSION['Request'] is now a reference to the Request getInstance();
when this session is closed the object will automatically be serialized - no need
to saveToSession or whatever!.... just make sure you have always declared the Request class
before you start the session.

so have the Request::getInstance() deal with checking/setting $_SESSION['Request'] internally.

> if ($_SESSION['Request']->isRefresh() ) {
> $_SESSION['Request']->saveToSession();
> /* etc. */
> exit();
> }
>
> /* Rest of script follows here */
>
> ?>
>
> IMHO the point of OOP is to keep each function split into the minimal
> functionality that you need. This allows you to reuse code easier
> because a function does only the *minimum* amount of work necessary
> instead of extra (unintended) functionality.
>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация