Page 1 of 1
[solved] Chicken and egg problem!
Posted: Thu Aug 25, 2005 7:05 am
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!
Posted: Thu Aug 25, 2005 7:35 am
by blacksnday
Session Start should always be first.
Posted: Thu Aug 25, 2005 7:58 am
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>
Posted: Thu Aug 25, 2005 8:03 am
by nielsene
Are you serilaizing objects into the session?
Posted: Thu Aug 25, 2005 8:07 am
by davidtee1
Eh?
Posted: Thu Aug 25, 2005 8:13 am
by nielsene
Have you stored an class into a session variable?
Posted: Thu Aug 25, 2005 8:15 am
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.
Posted: Thu Aug 25, 2005 8:15 am
by davidtee1
Yes I have. Is this a problem?
Posted: Thu Aug 25, 2005 8:18 am
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.
Posted: Thu Aug 25, 2005 8:18 am
by davidtee1
Thanks feyd and nielsene.
I now understand.