[solved] Chicken and egg problem!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
davidtee1
Forum Newbie
Posts: 18
Joined: Fri Jun 10, 2005 2:41 am

[solved] Chicken and egg problem!

Post by davidtee1 »

It appears I need to include any classes before I session_start().

However, the path to the file that has my classes is stored in a session variable which I cannot see until I session_start().

EG:

Code: Select all

include($_SESSION['systempath']."/classes.php");
session_start();
This doesn't find the classes.php coz the session variable cannot be found.


or

Code: Select all

session_start();
include($_SESSION['systempath']."/classes.php");
This errors or generally ignores attempts to access the class variables and functions.


So what do I do?

Which comes first the chicken [the session_start()] or the egg [the include()]

Any help gratefully appreciated!
Last edited by davidtee1 on Thu Aug 25, 2005 9:58 am, edited 1 time in total.
User avatar
blacksnday
Forum Contributor
Posts: 252
Joined: Sat Jul 30, 2005 6:11 am
Location: bfe Ohio :(

Post by blacksnday »

Code: Select all

session_start();
Session Start should always be first.
davidtee1
Forum Newbie
Posts: 18
Joined: Fri Jun 10, 2005 2:41 am

Post by davidtee1 »

But then I get this error sometimes:

Code: Select all

Fatal error: Unknown(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition <b>table</b> of the object you are trying to operate on was loaded _before_ the session was started in <file>
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Are you serilaizing objects into the session?
davidtee1
Forum Newbie
Posts: 18
Joined: Fri Jun 10, 2005 2:41 am

Post by davidtee1 »

Eh?
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Have you stored an class into a session variable?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you have a class called 'table' stored inside the session. Class 'table' hasn't been defined yet, so the session system can't reconstitute the object.
davidtee1
Forum Newbie
Posts: 18
Joined: Fri Jun 10, 2005 2:41 am

Post by davidtee1 »

Yes I have. Is this a problem?
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

No, but that's why you need to include the class definitions before you can start the session.

Why do you need to stick a path variable into the session? Is there anyway to convert the path variable to a constant, a configuration file, include_path, or url_parsing tricks?

basically you need to get to a place where you can do

Code: Select all

require_once("paths.inc");
require_once("class_definitions.inc");
session_start();
Of course none of the inclues can generate any output before the session_start, but that shouldn't be a problem.
davidtee1
Forum Newbie
Posts: 18
Joined: Fri Jun 10, 2005 2:41 am

Post by davidtee1 »

Thanks feyd and nielsene.

I now understand.
Post Reply