Jump to content

Fatal error: Call to a member function on a non-object in


ikanku15

Recommended Posts

hi all, im a newby in this php thing.

 

im doing a websites which use the oop php structure. im using php 4.4.8

 

somehow, i got this problem occur:

 

Fatal error: Call to a member function on a non-object in /var/www/crmctt/someDir/someName.php on line 153

 

the code will be some thing like this:

 

<?php
/*
	//
	// IncidentModel.php
	// this model class stores only business logic
	// data is stored in the entity class
	//
*/

include_once MODELPATH . 'Model.php';
include ENTPATH . 'Incident.php';
include ENTPATH . 'IncidentType.php';
include ENTPATH . 'ServerDomain.php';
include ENTPATH . 'ServerHostName.php';
include ENTPATH . 'ServerIP.php';
include ENTPATH . 'ServerLocation.php';
include ENTPATH . 'FQDN.php';
include ENTPATH . 'DateTime.php';


class IncidentModel extends Model
{
	var $addSuccess;
	var $incident;
	var $loc;
	var $dom;
	var $host;

	/*
		//
		// Constructor: IncidentModel()
		// Description: The incident model of the system
		// Parameter: $request->httpPost = the information posted by the member
		//
	*/
	function IncidentModel($request = NULL, $user = NULL, $dao = NULL)
	{
		// super constructor 
		$this->Model($request, $user, $dao);

		if($this->request->GetHttpPost())
		{
			$this->ProcessRequest();
		}
	}

	/*
		//
		// Method: ProcessRequest()
		// Description: Process the request
		//
	*/
	function ProcessRequest()
	{
		// local variables
		$fqdn = NULL;
		$type = NULL;
		$email = NULL;
		$startDateTime = NULL;
		$endDateTime = NULL;

		// validation

		// fqdn: after everything gone ok then the fqdn will be available at $this->fqdn
		$fqdn = $this->GetFQDN(
			$this->request->httpPost['ABM_location'], 
			$this->request->httpPost['ABM_host'], 
			$this->request->httpPost['ABM_domain'], 
			'Please make sure the selection of FQDN is correct');

		// validate the type of incident
		if(!$this->ValidateIsBlank($this->request->httpPost['ABM_type'], 
			'Please select a type of incident.'))
		{
			// query database to get the complete information 
			// create type object
			$type = new IncidentType($this->request->httpPost['ABM_type'], 'some action');
		}

		// time and date
		// start date time
		$startDateTime = new DateTime(
			$this->request->httpPost['ABM_startTimeHour'], 
			$this->request->httpPost['ABM_startTimeMinutes'], 
			0, 
			$this->request->httpPost['ABM_startDateMonth'], 
			$this->request->httpPost['ABM_startDate'], 
			$this->request->httpPost['ABM_startDateYear']);
		$this->ValidateDateTime($startDateTime, 'The start time and date information provided is invalid, please re-check.');
		// end date time
		$endDateTime = new DateTime(
			$this->request->httpPost['ABM_endTimeHour'], 
			$this->request->httpPost['ABM_endTimeMinutes'], 
			0, 
			$this->request->httpPost['ABM_endDateMonth'], 
			$this->request->httpPost['ABM_endDate'], 
			$this->request->httpPost['ABM_endDateYear']);
		$this->ValidateDateTime($endDateTime, 'The end time and date information provided is invalid, please re-check.');
		$this->ValidateDateRange($startDateTime, $endDateTime, 
			'The date range provided is invalid, please check the time and date settings.');

		// the reason
		$this->ValidateIsBlank($this->request->httpPost['ABM_reason'], 'Please fill in the reason field');

		// the description
		$this->ValidateIsBlank($this->request->httpPost['ABM_description'], 'Please fill in the description field');

		// the email
		// first, we strip off the spaces
		if(!$this->ValidateIsBlank($this->request->httpPost['ABM_email'], 'Please enter an email address'))
		{
			$email = str_replace(' ', '', $this->request->httpPost['ABM_email']);
			// then we explode the list
			$email = explode(',', $email);
			// next we loop through the array
			for($i = 0; $i < count($email); $i++)
			{
				$this->ValidateEmail($email[$i], 
					'The email address %email% entered is invalid.');
			}
		}


		// object instantiation 

		// everything is checked
		// create the entity with complete/broken information
		$this->SetIncident(new Incident(
			$this->user,
			$fqdn,
			$type,
			$startDateTime,
			$endDateTime,
			$this->request->httpPost['ABM_reason'],
			$this->request->httpPost['ABM_description'],
			$this->request->httpPost['ABM_email']
		));	


		// database access & email triggering 

		// query to the database if everything is okay
		// check the statusMsg
		if(!count($this->GetStatusMsg()))
		{
			// data access through the data access object
			$this->dao->ExecuteQuery(sprintf("INSERT INTO `incident`" . 
				" (`fID`, `uID`, `inTypeID`, `inStartDateTime`, `inEndDateTime`, `inReason`, `inDescription`, `inEmail`, `inLastUpdate`)" .
				" VALUES(%d, %d, %d, %d, %d, '%s', '%s', '%s', %d)",
				mysql_real_escape_string($this->incident->fqdn->GetFID(), $this->dao->GetDBConn()),
				mysql_real_escape_string($this->user->GetID(), $this->dao->GetDBConn()),
				mysql_real_escape_string($this->incident->type->GetTypeID(), $this->dao->GetDBConn()),
				mysql_real_escape_string($this->incident->startDateTime->GetTimestamp(), $this->dao->GetDBConn()), 
//someCode....

 

the line 153 will be:

 

mysql_real_escape_string($this->incident->startDateTime->GetTimestamp(), $this->dao->GetDBConn()),

 

can anyone help me on this?  ???

Link to comment
Share on other sites

That means that something you thought is an object actually isn't one.  Try checking each one individually until you find the culprit.  You can use var_dump(), and/or is_object().  Put your checks on the line before the line with the error.  You'll need to check $this->incident, then $this->incident->startDateTime, and so on.

Link to comment
Share on other sites

hi btherl, thx for ur quick reply.

 

i hv used the var_dump() to check on the error line. this error come out:

 

Parse error: syntax error, unexpected T_STRING in /var/www/someDir/someName.php on line 154

 

line 154 still refer to the same error line before and i got no idea what is it.

Link to comment
Share on other sites

this code is more detail

 

$this->dao->ExecuteQuery(sprintf("INSERT INTO `incident`" . 
				" (`fID`, `uID`, `inTypeID`, `inStartDateTime`, `inEndDateTime`, `inReason`, `inDescription`, `inEmail`, `inLastUpdate`)" .
				" VALUES(%d, %d, %d, %d, %d, '%s', '%s', '%s', %d)",
				mysql_real_escape_string($this->incident->fqdn->GetFID(), $this->dao->GetDBConn()),
				mysql_real_escape_string($this->user->GetID(), $this->dao->GetDBConn()),
				mysql_real_escape_string($this->incident->type->GetTypeID(), $this->dao->GetDBConn()),
				var_dump() // <---- i have added this to the code to check
				mysql_real_escape_string($this->incident->startDateTime->GetTimestamp(), $this->dao->GetDBConn()), // <---- the code line that generate the error
				mysql_real_escape_string($this->incident->endDateTime->GetTimestamp(), $this->dao->GetDBConn()),
				mysql_real_escape_string($this->incident->GetReason(), $this->dao->GetDBConn()),
				mysql_real_escape_string($this->incident->GetDescription(), $this->dao->GetDBConn()),
				mysql_real_escape_string($this->incident->GetEmail(), $this->dao->GetDBConn()),
				mysql_real_escape_string(time(), $this->dao->GetDBConn()))); 

Link to comment
Share on other sites

ikanku, remove the var_dump() you added and add this code outside your ExecuteQuery (on the line before):

 

print "\$this->incident looks like this: ";var_dump($this->incident);print "<br>\n";
print "\$this->incident->startDateTime looks like this: ";var_dump($this->incident->startDateTime);print "<br>\n";
$this->dao->ExecuteQuery( ...

 

And see what it outputs.  It should tell you exactly which thing is not an object.  Then you need to work out why it isn't an object.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.