Reply to Re: Autoloading class definitions of composed objects on unserialize() from session

Your name:

Reply:


Posted by gosha bine on 05/14/07 17:16

On 14.05.2007 17:53 carrion wrote:
> Hello everyone!
> I'm currently working on a MVC-framework and have run into an issue.
>
> I'm using separate script files to render the active page's CSS and
> Javascript Code.
> I want to pull the data from the page controller object, which is
> initialized in another script.
> I thought this wouldn't be a problem if I simply stored the controller
> in the session-file, but the unserialization of the object simply
> won't work.

This is actually far from "simple". PHP wasn't designed with object
persistence in mind and your best bet is to follow its "share nothing"
approach.

> The controller has properties that are of different class types than
> the controller itsself (page-secific Model and View objects).

Just rebuild it from scratch using parameters passed in request or session.

>
> My Questions:
>
> 1. Are there any problems using $myObj=$_SESSION['myObj']; ?
> I thought that as of PHP5 this should work?
>
> 2. do class definitions of contained objects also have to be known
> when i unserialize?
> (like my Model/View objects)

Yes. See http://www.php.net/manual/en/language.oop.serialization.php

>
> 3. can I get __autoload to help me out of this?

__autoload is a hack, you'd better stay away from it. ;)

>
> 4. if not, can i perform some sort of __sleep()/__wakeup() magic to
> achieve the same effect?

IIRC, wakeup() is called when object is already constructed, not when
the classes are loading.


--
gosha bine

extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok

[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

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