Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > PHP

Reply
 
LinkBack Thread Tools Display Modes
Old 07-15-2007, 12:14 PM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,532
sde is on a distinguished road
Did you know? (storing objects in sessions)

When storing your custom object in a session, the object class needs to be declared before session_start();.

Wrong way
PHP Code:
<?php
session_start
();

require_once(
'MyClass.php');

if (!
$_SESSION['myobj']) {
  
$_SESSION['myobj'] = new MyClass();
}

$obj $_SESSION['myobj'] ;
?>
When the object is already stored in the session, this will generate the error:
Quote:
PHP_Incomplete_Class
Right way
PHP Code:
<?php
require_once('MyClass.php');
session_start();

if (!
$_SESSION['myobj']) {
  
$_SESSION['myobj'] = new MyClass();
}

$obj $_SESSION['myobj'] ;
?>
Makes sense, but had me stumped for a bit.
__________________
Mike
sde is offline   Reply With Quote
Old 07-15-2007, 01:39 PM   #2 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,175
Belisarius is on a distinguished road
That's the way I'd do it anyways, but your right - I wouldn't have figured that including it after the start of the session would have caused problems, especially with that error message.
__________________
GitS
Belisarius is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Game project. I need some help. Rafkin Platform/API C++ 5 12-15-2005 10:16 PM
Sorting an array of any Comparable objects plague Java 1 03-14-2005 07:24 PM


All times are GMT -8. The time now is 09:04 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting