I need to pass variables found in parent class to the extended class, but all i get is a notice that the variables are undefined.
I am not sure what is wrong and my gut says that this is an easy fix, but for some reason i can not see it.
<?php
class trackem {
public $hostnm;
public $ip;
public $info;
public function __construct() {
}
public function getNm($hostnm){
$hostnm = gethostbyaddr($_SERVER['REMOTE_ADDR']);
//echo $hostnm;
}
public function getIp($ip){
$ip = $_SERVER['SERVER_ADDR'];
//echo $ip;
}
public function getBrws($info){
$info = get_browser(null, true);
//print_r($info);
}
}
class trackem2file extends trackem{
function wrtInfo(){
//parent::getBrws($info);
//parent::getIp($ip);
//parent::getNm($hostnm);
parent::__construct();
$this->hostnm = parent::getNm($hostnm);
$this->ip = parent::getIp($ip);
$this->info = parent::getBrws($info);
$this->filename = 'txt/trackfile.txt';
$this->fh = fopen($this->filename, 'w');
fwrite($this->fh, $this->hostnm . '\r\n');
fwrite($this->fh, $this->ip . '\r\n');
fwrite($this->fh, $this->info . '\r\n');
fwrite($this->fh, '--------------------' . '\r\n');
fclose($this->fh);
}
}
$track2 = new trackem2file();
$track2->wrtInfo();
?>
I have tried to find a solution to this for about 2 days now, and I have read some other posts about object inheritance and variables not being loaded to extended classes but was not helpful enough to help me solve this problem. So I now ask for your help.
Thanks in advance.
You need to use them like this, you missed out the
$this->:Try this: