Re: A no brainer...

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

 



On Friday 13 October 2006 20:18, Tony Di Croce wrote:
> Is their a slick way of automatically serializing Objects to the session
> when a script exit()'s and de-serialize them in session_start()?
>
> It seems to me that object oriented PHP might actually be useful if I could
> persist an object across an entire session, and come to think of it, their
> really ought to be an automatic way to do this... (IE, I'd not be suprised
> one bit if its already a feature of PHP that I'm just not aware of)...
>
> So, is their a way to do this?

class Foo {
...
}

session_start();
$foo = new Foo();
$_SESSION['myfoo'] = $foo;

Ta da.  The catch is the class must be defined before you start the session, 
so that it knows how to deserialize it.

Of course, the cost of serialization and deserialization is non-trivial for 
any data structure that is of interesting size, and you have to keep in mind 
that if you aren't syncing to the database periodically then you will end up 
with stale data objects.  (An issue in any case, but the longer the object 
representing a view of your database exists, the more of a problem it 
becomes.  YMMV depending on the data you're holding.)

-- 
Larry Garfield			AIM: LOLG42
larry@xxxxxxxxxxxxxxxx		ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[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