php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29202 Weird Session/class problem
Submitted: 2004-07-16 09:29 UTC Modified: 2004-12-20 22:29 UTC
Votes:6
Avg. Score:4.5 ± 0.5
Reproduced:5 of 5 (100.0%)
Same Version:2 (40.0%)
Same OS:2 (40.0%)
From: phreakeehacker at hotmail dot com Assigned:
Status: Not a bug Package: Session related
PHP Version: 5.0.0 OS: Linux Fedora Core 2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: phreakeehacker at hotmail dot com
New email:
PHP Version: OS:

 

 [2004-07-16 09:29 UTC] phreakeehacker at hotmail dot com
Description:
------------
I have three classes I'm using in this demo.  One class extends a base class, and one class is a container class.  If I INCLUDE the base class from a file, it will run the first time, but when I click the submit button I get the error message "Fatal error: container::showNodes() [function.showNodes]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition <b>unknown</b> of the object you are trying to operate on was loaded _before_ the session was started in /var/www/html/nodetest.php on line 20".

If I simply include the file 'node.php' literally then it works flawlessly.  So it appears to me that somehow the included code is handled differently when it is included via a file than if it were simply pasted literally into the same script in the same exact spot.  I've tried all variations of includes (include_once, require, require_once) and nothing seems to make a difference.  It also seems to have to do with the session not being able to sort out which class the object is if the object definition is included via the file.

Any ideas on this one?

Reproduce code:
---------------
Two files are needed for this bug, which are located at this URL:

http://www.j2.net/~bholyoak/nodetest.txt


Expected result:
----------------
I expect it to work the same if the file were included as it works if the code were literally pasted in instead of included.

Actual result:
--------------
The script runs fine the first time.  When I click the submit button, it gives me this error:

"Fatal error: container::showNodes() [function.showNodes]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition <b>unknown</b> of the object you are trying to operate on was loaded _before_ the session was started in /var/www/html/nodetest.php on line 20"

It DOESN'T give me this error if the code is pasted directly in instead of included.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-10-12 19:52 UTC] phreakeehacker at hotmail dot com
Sorry, the link to the code examples changed to this: http://www.jtoo.net/~bholyoak/nodetest.txt
 [2004-12-07 08:50 UTC] tony2001@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

The error message you get is rather clear: you need to ensure that class definition of the object, that is stored in the session, is known *before* the session is started.
Move session_start() call after all class definitions and it'll work fine.
That's expected behaviour.
 [2004-12-20 22:29 UTC] phreakeehacker at hotmail dot com
Hi Tony,

Thank you for your reply.  I already know that if I move the session_start I can get it to work.  That's not the problem.  Please read my post more carefully, since I did take a considerable amount of time trying to understand why it does what it does.  The moving of the session_start is not the problem.  It's the fact that it works when the code is included inline, but when it's included with the "include" directive it gives me the error.  I'm assuming it's because the inline code is processed differently than if it is included with the "include" directive.  Please double check my post.  If the included code is handled differently than if it were right inline, please direct me to a place I can read more details about how the code is processed in this situation.  Otherwise, it makes sense to me that the script should be compiled exactly the same if the code is inserted via "include" or right inline.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 20:01:31 2024 UTC