Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #2070

Re: object in $_SESSION

From Jerry Stuckle <jstucklex@attglobal.net>
Newsgroups comp.lang.php
Subject Re: object in $_SESSION
Date 2011-06-10 06:46 -0400
Organization A noiseless patient Spider
Message-ID <isssmp$j2o$1@dont-email.me> (permalink)
References <22afddc3-4675-4838-af25-dc13aa75a2e0@c20g2000vbv.googlegroups.com>

Show all headers | View raw


On 6/10/2011 4:02 AM, Jivanmukta wrote:
> Hello,
> I need your opinions about my solution of some programming probem. I
> have little experience in web developement and PHP.
> I have a page insert_send.html with a form. The user enters into the
> form path of HTML file with bank statement and presses submit button.
> Then import_statement.php program is executed. The program imports
> bank statement into Statement object (which is complicated task) and
> runs:
>    $_SESSION['statement'] = serialize($statement);
>    headerLocation('send_emails.php');
> Then send-emails.php program is executed. It runs:
>    $statement = unserialize($_SESSION['statement'];
> and sends emails according to statement positions (which is
> complicated task, too).
> My question: is the method of transferring Statement object through
> session array acceptable in my case? One man told me that passing
> objects through sessions is usually an error, but I don't know why.
> I decided to separate importing of bank statement and sending emails
> into two different files becase of complexity of these tasks.
> Please help. Thanks in advance.
>
> newbie

You don't have to serialize() the object; just storing it in the session 
is sufficient.

Erwin's comments about what the object can contain are very valid. 
However, I don't consider it an error to pass an object through a 
session; it's no different than any other variable.  And often it is 
more efficient to pass the entire object through the session than doing 
something like passing an id and rebuilding the object from a database 
query.

The real "problem" here is PHP's handling of objects.  When your script 
ends, PHP calls the destructor for the class.  But when it is 
deserialized, PHP does not call the constructor.  This creates a 
situation where there can be more destructors called than constructors - 
a clear violation of OO principals.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Back to comp.lang.php | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

object in $_SESSION Jivanmukta <jivanmukta@poczta.onet.pl> - 2011-06-10 01:02 -0700
  Re: object in $_SESSION Erwin Moller <Since_humans_read_this_I_am_spammed_too_much@spamyourself.com> - 2011-06-10 11:20 +0200
    Re: object in $_SESSION Gregor Kofler <usenet@gregorkofler.com> - 2011-06-10 15:43 +0200
      Re: object in $_SESSION Jivanmukta <jivanmukta@poczta.onet.pl> - 2011-06-10 09:19 -0700
        Re: object in $_SESSION Jerry Stuckle <jstucklex@attglobal.net> - 2011-06-10 12:34 -0400
        Re: object in $_SESSION Gregor Kofler <usenet@gregorkofler.com> - 2011-06-10 18:41 +0200
  Re: object in $_SESSION Jerry Stuckle <jstucklex@attglobal.net> - 2011-06-10 06:46 -0400

csiph-web