Jump to content

Fatal error: Using $this when not in object context


clankill3r

Recommended Posts

First i will show the code that activates the error:

 

		if($current_host != null) {
		print_r2("1");
		print_r2($current_host);
		print_r2($current_foundResult);
		print_r2("2");
		$current_host::addFoundResult($current_foundResult);
	}

 

this is the output:

 

1

 

Host Object

(

    [hostname] => www.google.nl

    [foundResults] => Array

        (

        )

 

)

 

FoundResult Object

(

    =>

    [title] =>

    [visits] =>

)

 

2

 

 

Fatal error: Using $this when not in object context in ~~~~~~~~~~~~~ on line 385

 

the error comes from this line:

$this->foundResults[] = $foundResult;

 

 

class Host {

public $hostname;
public $foundResults;

public function __construct($hostname) {
	$this->hostname = $hostname;
	$this->foundResults = array();
}

public function addFoundResult($foundResult) {
	$this->foundResults[] = $foundResult;
}
}

 

what i don't get about it is that both the Host Object and the FoundResult Object exist...

$current_host::addFoundResult($current_foundResult);

:: calls methods statically, which means there is no $this to use. You don't get any of the variables (like hostname and foundResults) either.

 

Use -> to call methods normally.

$current_host->addFoundResult($current_foundResult);

 

And while you're at it, read through the PHP OOP manual.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.