NYCPHP Meetup

NYPHP.org

[nycphp-talk] PHP5 Static Classes

Joseph Crawford codebowl at gmail.com
Mon Mar 7 17:42:16 EST 2005


I would also like to note that if you combine OOP and sessions you
dont have to re-create each object.  for my members area i created a
user class that is stored in the users session, based on each page
load it checks to see if the session is set, if so it continues if not
it creates a new object and set's it to session, something like this

include('classfile.php');
session_start();

if( isset( $_SESSION['user'] ) ) {
  $user = &$_SESSION['user'];
} else {
  $user = new User();
  $_SESSION['user'] = &$user;
}

then you can use $user throught your application and it will update
the session object as you use it :D

This causes less overhead of having to re-create the object and to
store all data into the db with each page load.  You can go through
several pages, then in the end store the data from the object.


-- 
Joseph Crawford Jr.
Codebowl Solutions
codebowl at gmail.com



More information about the talk mailing list