[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2001-06-15
5
Medium Priority
?
183 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 450 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses
Course of the Month18 days, 10 hours left to enroll

834 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