Solved

Urgent - use of 'require' and 'include' and session variables

Posted on 2001-06-15
5
167 Views
Last Modified: 2013-11-18
I?m using session variables to store objects and I?m having problems with different versions of PHP. Two files:-

//-------------
//start rjp.rqd
//-------------

<?
class test()
{
     function doEcho()
     {
          echo ?hello<BR>?;
     }
}
?>
//-----------
//end rqp.rqd
//-----------


//-------------
//start rjp.php
//-------------

<?
session_start();
session_register(?theTest?);
session_register(?Count?);
require (?rjp.rqd?);

$Count++;
if (!isset($theTest))
{
     $theTest = new test;
     echo ?test instantiated<BR>?;
}

$theTest->doEcho();
?>
You have visited this site <?echo $Count?> times<BR>
<A HREF=<?echo $PHP_SELF?>?<?=SID?>>page again</A>

<?
//-----------
//end rjp.php
//-----------
?>

This works fine on PHP version 4.0.1pl2 but gives the following error on PHP version 4.0.3pl1 (and 4.0.4pl1) when ?page again? is hit:-

Fatal error: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition test of the object you are trying to operate on was loaded _before_ the session was started in /testdir /rjp.php

I?ve cut the rqd file into the php file (so it?s actually part of the php file and not ?required?) and it works fine on both php versions.

register_vars, track_vars and enable_trans_sid are all enabled.

What am I doing wrong?

RJP.
0
Comment
Question by:rplewka
  • 2
  • 2
5 Comments
 
LVL 15

Accepted Solution

by:
a.marsh earned 150 total points
ID: 6194865
I would move the require line before the session_start() line.

So your code becomes:

require (?rjp.rqd?);
session_start();
session_register(?theTest?);
session_register(?Count?);

Ant
0
 

Author Comment

by:rplewka
ID: 6195380
Ant,

I'll give that a try and see what happens.

I'll let you know how it goes.

RJP
0
 
LVL 5

Expert Comment

by:aksteve
ID: 6208144
Classes should be included before any other code if for anything other then readability.

session_register automatically issues a session_start so your use of session_start is redundant..
0
 

Author Comment

by:rplewka
ID: 6215233
Thank a.marsh, that did the trick. Actually sorted it out at the weekend, but so busy didn't have time to respond. Thanks again.
0
 
LVL 15

Expert Comment

by:a.marsh
ID: 6215255
Glad to help.........if it did the trick though, I'm curious as to why I only deserved a B grade......

:o\

Ant
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

823 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question