Mombu the Php Forum sponsored links

Go Back   Mombu the Php Forum > Php > Incomlete object?
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 8th February 12:54
lüpher_cypher
External User
 
Posts: 1
Default Incomlete object?



Hi,

I have a few classes, and I keep objects of those in session. I now got
an error saying that I am trying to access a method of an incomplete
object. Just can't figure it out now - anyone has ideas? The inclusion
hierarchy is as follows:

index.php -> class Page, starts session, in constructor inits database
access as object of class DB
class Page -> includes class Form_Register, inherited from class Form
class Form_Register tries to access database via object of DB, at which
point I get an error that it is incomplete (DB is stored in session as well)

Any ideas? I tried to close the browser (destrot session) and reopen it,
but it's still the same..

Thank you,
Lüph
  Reply With Quote


  sponsored links


2 8th February 12:54
steve
External User
 
Posts: 1
Default Incomlete object?



no line numbers? no specific error messages? that helps.

have you tried commenting code and uncommenting until you hit the error. i'm
not a big fan of "write the test before the code" but you should certainly
have some kind of testing framework in place so you can see exactly when and
where the introduction of code either alters or breaks desired behavior.

those are the first things i'd do to fix the problem...everything else is as
random as shooting for mark...in the dark. perhaps you'll hit it eventually
should you choose some alternate course of action.

hth,

me


| Hi,
|
| I have a few classes, and I keep objects of those in session. I now got
| an error saying that I am trying to access a method of an incomplete
| object. Just can't figure it out now - anyone has ideas? The inclusion
| hierarchy is as follows: |
| index.php -> class Page, starts session, in constructor inits database
| access as object of class DB
| class Page -> includes class Form_Register, inherited from class Form
| class Form_Register tries to access database via object of DB, at which
| point I get an error that it is incomplete (DB is stored in session as
well)
|
| Any ideas? I tried to close the browser (destrot session) and reopen it,
| but it's still the same..
|
| Thank you,
| Lüph
  Reply With Quote
3 8th February 12:55
janwillem borleffs
External User
 
Posts: 1
Default Incomlete object?


And here it is where it goes wrong; you cannot store resources in sessions.
Therefore, your code should test the connection and attempt to set up a new
one when applicable.


JW
  Reply With Quote
4 8th February 22:40
joel wan
External User
 
Posts: 1
Default Incomlete object?


Lupher is right, resources cannot be placed in SESSION variables but
you can store entire objects in the session by serializing the object
for eg:

$_SESSION['myObject'] = serialize($myObject);

and on the other page, $myObject = unserialize($_SESSION['myObject'];

then $myObject->attribute will be available.
  Reply With Quote
5 8th February 22:40
steve
External User
 
Posts: 1
Default Incomlete object?


| Lupher is right, resources cannot be placed in SESSION variables but
| you can store entire objects in the session by serializing the object
| for eg:
|
| $_SESSION['myObject'] = serialize($myObject);
|
| and on the other page, $myObject = unserialize($_SESSION['myObject'];
|
| then $myObject->attribute will be available.


is this a new revelation for you, joel? he wasn't making a point. he was
trying to figure out why he is getting a specific error. can you help with
that?
  Reply With Quote
6 8th February 22:40
joel wan
External User
 
Posts: 1
Default Incomlete object?


Sorry, I meant Janwillem Borleffs is right, not Lupher.

Since Lupher says he gets an incomplete object, my solution is to
serialize the object ********ely into the session variable. That was my
suggestion.
  Reply With Quote
7 8th February 22:41
steve
External User
 
Posts: 1
Default Incomlete object?


Nope, a serialised resource is still a resource. When it's unserialised
in a new page it is no longer valid. Next suggestion?

---
Steve
  Reply With Quote
8 8th February 22:41
joel wan
External User
 
Posts: 1
Default Incomlete object?


From: http://ca3.php.net/session
Some types of data can not be serialized thus stored in sessions. It
includes resource variables or objects with circular references (i.e.
objects which passes a reference to itself to another object).

Then I suggested serialize the OBJECT, which in Luther's case isn't a
resource but a simple database object.

how about you wait for Luther to respond before you start an unecessary
discussion.
  Reply With Quote
9 8th February 22:41
steve
External User
 
Posts: 1
Default Incomlete object?


will do...wait...i *did*.

my point was that your suggestion was not even applicable to his problem.
you explained how to serialize objects and unserialize them. great. where
does that get the op?

janwillem borleff nailed it on the head...which is probably the reason we
haven't heard back from the op.

| From: http://ca3.php.net/session
| Some types of data can not be serialized thus stored in sessions. It
| includes resource variables or objects with circular references (i.e.
| objects which passes a reference to itself to another object).

almost snipped the above quote...do i need to read that? does this help
anyone in this thread?

| Then I suggested serialize the OBJECT, which in Luther's case isn't a
| resource but a simple database object.

and, given that you yourself recognize that the resource luther is trying to
use is a db object, i find it odd (yet again) that you'd go down a frivilous
path of explaining how one can serialize objects when it won't make a rat's
ass of difference in the end. this is NOT his problem. why try to divert?


| how about you wait for Luther to respond before you start an unecessary
| discussion.

the unnecessary discussion is born of you in the form of serializing
objects. even so, the op has not responded and i presume it is b/c of
janwillem's explanation - which was spot-on.

i recognize your feeling are ruffled at this point...i'm not going to say
i'm sorry. stick to solving the problem and not growing more trees for the
forest.
  Reply With Quote
Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666