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

Link to comment
Share on other sites

$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.

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.