berridgeab Posted September 5, 2011 Share Posted September 5, 2011 Hello I am struggling to store a simple PHP class within a PHP session. When I try to access the class stored in my session I get the following "Fatal error: main(): The script tried to execute a method or access a property of an incomplete object." Google tells me this is because I haven't included my class definition before calling session_start(). The solution would be to require_once() every PHP class my site uses before calling session_start(). Only thing is there are about 100 classes. Would this not add a ton of overhead to every PHP page that loads (Because it is loading 90+ unneeded classes) or is this common practice? Currently I only require_once() the classes I need on a per page basis so I reduce overhead. But most of these require_once() calls come after I have called session_start(). Quote Link to comment https://forums.phpfreaks.com/topic/246463-incomplete-object-stored-in-session/ Share on other sites More sharing options...
trq Posted September 5, 2011 Share Posted September 5, 2011 You only need to require the class you have stored in the session before calling session_start(). Quote Link to comment https://forums.phpfreaks.com/topic/246463-incomplete-object-stored-in-session/#findComment-1265602 Share on other sites More sharing options...
berridgeab Posted September 5, 2011 Author Share Posted September 5, 2011 Yes I can do, but that could be any one of 25 - 50 classes and my session_start() happens quite early on. The only solution I can see is to have some way of loading my required classes before the session_start() is called but thats quite a big project rewrite. Thanks anyway. Quote Link to comment https://forums.phpfreaks.com/topic/246463-incomplete-object-stored-in-session/#findComment-1265608 Share on other sites More sharing options...
berridgeab Posted September 5, 2011 Author Share Posted September 5, 2011 Ive gone against the rewrite. Ive decided to let MySQL take the performance hit instead and load the classes on each page rather than putting them in a session. Quote Link to comment https://forums.phpfreaks.com/topic/246463-incomplete-object-stored-in-session/#findComment-1265638 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.