Jump to content

"Call to a member function on a non-object"


Bladescope

Recommended Posts

Error:

Fatal error: Call to a member function report() on a non-object in C:\AppServ\www\Portfolio\AppManv2\modules\questions.php on line 48

 

Line 48:

	$error->report("Step $step is non existant.");

 

error class:

<?php
class error {

// Set the Vars
private $return = "<div style='width: 300px; border: 1px solid black'><h3>Error Report</h3>{report}</div>";
private $errortemp = "<p><b>Error:</b> {error}</p>";
private $errorcol;

// Handle the report input
public function report($report) {
	$this->errorAdd($report);
}

// Add an error to the report
private function errorAdd($report) {
	$report = str_replace('{error}', $report, $this->errortemp);
	$this->errorcol .= $report;
}

// Generate Report
public function getReport() {
	if ($this->errorcol) {
		$report = str_replace('{report}', $this->errorcol, $this->return);
		print $report;
	}
}
}
$error = new error();
?>

 

The script is run from a file, which includes error.php at the top, then declares it's classes. A class called from lower down in the script includes questions.php, and generates that.

 

Any tips, or do you need more info?

Link to comment
Share on other sites

Edit: I tested it on the same page and it worked, so this is how the pages are linked

main page include()s error.php at the top of the script.

main page then creates an abstract class which contains a public static method that includes questions.php.

main page then calls (statically) the method.

 

So, in theory, the following should happen

Main page includes error.php

-> error class is created

-> error object is created

Main page creates class + method containing include to questions.php

Main page calls the method

-> questions.php is included

->-> script runs a method from the error object

 

except the script doesnt run a method because it says the method and object don't apparantly exist

Link to comment
Share on other sites

This apparantly works, so thanks, but this raises a little issue.

 

You see, as you know from the error class script, it calls upon getReport to generate the error report. The getReport method is invoked after the method that includes questions.php has been invoked, yet it produces nothing. But if I place it in questions.php, it generates the report.

 

Now, I could easily surpass it just by deleting the method and simply writing it to a file, adding it to a database or just by simply echoing it out each time an error occurs, but is there any way to keep the script and somehow get the class to work through include()?

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.