Solved

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

Posted on 2001-06-15
5
174 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
MySQL limit and not so limited 13 41
PHP encrypted string and passing to a ASP Page 12 50
blocking the posted data from outside of my domains 8 24
JSON decode 5 21
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

726 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