Page 1 of 1

Fatal Error: incomplete object because of session

Posted: Sat Jun 28, 2003 8:45 am
by patrikG
The scenario:

My form-class works fine and does exactly what I want. However, when I register a session-variable (session was already started by another page) I get
Fatal error: Unknown(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition <b>formarray</b> of the object you are trying to operate on was loaded _before_ the session was started in "...campaign_quotes.php" on line 51
Line 51 is where the function-call to a form-class method is made, i.e.

Code: Select all

echo $form->createFormField($formItemProperties,$parameters);

The code:

Code: Select all

<?php
require_once("class_campaign.inc.php");
require_once("class_mysql.inc.php");
include_once("class_forms.inc.php");

$sql		=new mod_db;
$form		= new formClass;
$campaign	= new campaignclass;

session_register("campaign");

include_once("HTMLTemplates/campaign_header.html");
?>
	<FORM name="cms" action="submit_quotes.php" method="post" onSubmit="return false;">
	<input type=hidden name="quoteID" id="quoteID" value="<?=$_POST["id"]?>">
		<TABLE cellspacing="0" cellpadding="0" border="0" width="100%">
			<TR>
				<TD>
					<TABLE cellspacing="2" cellpadding="3" border="0" width="100%">
						<TR>
							<TD class="mainHeaderGreen" align="center"><B>Adding Quotes</B>
							</TD>
						</TR>
						<TR>
							<TD class="bluetext"><B>Quote</B></TD>
						</TR>
						<TR>
							<TD valign="top" colspan="2" class="bluetext">
				<?
				$formItemProperties	=	array(	"fieldType"=>"text",
												"fieldId"=>"quote",
												"fieldValidate"=>true,
												"fieldValidateText"=>"Please enter a quote.",
												"fieldRequired"=>true,
												"maxLength"=>200);
				$parameters			=	array(	"class"=>"forminput",
												"type"=>"textarea",
												"cols"=>"50",
												"rows"=>"4",
												"value"=>"$campaign->quote");
				echo $form->createFormField($formItemProperties,$parameters);
				?>
							</TD>
						</TR>
etc...
Now, if I remove the session, i.e. the line

Code: Select all

session_register("campaign");
, everything works fine and does exactly what it's supposed to do. But I do need the session_variable in that page to assign values (if set) to the form-fields.

I know I could write a work-around if I let Javascript write the values, but that's rather untidy and I don't like it. I just can't figure out what really causes this error:
the class is correctly defined and working
the code in this page is fine and working

only the session screws it up.... :roll:

Posted: Sat Jun 28, 2003 8:52 am
by Bill H
session_register() is not recommended under the newer version of PHP.
Have you tried using the $_SESSION array instead?
(I also didn't see a session_start() call there.)

Posted: Sat Jun 28, 2003 8:55 am
by patrikG
thanks! what a stupid mistake. :oops: