[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…
Suggested Courses

649 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