clankill3r Posted November 10, 2011 Share Posted November 10, 2011 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 https://forums.phpfreaks.com/topic/250904-fatal-error-using-this-when-not-in-object-context/ Share on other sites More sharing options...
requinix Posted November 10, 2011 Share Posted November 10, 2011 $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 https://forums.phpfreaks.com/topic/250904-fatal-error-using-this-when-not-in-object-context/#findComment-1287226 Share on other sites More sharing options...
clankill3r Posted November 11, 2011 Author Share Posted November 11, 2011 2 times thanks Link to comment https://forums.phpfreaks.com/topic/250904-fatal-error-using-this-when-not-in-object-context/#findComment-1287445 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.