Note that there are some explanatory texts on larger screens.

plurals
  1. POIssue using parent variables in extended class
    text
    copied!<p>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.</p> <p>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.</p> <pre><code>&lt;?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-&gt;hostnm = parent::getNm($hostnm); $this-&gt;ip = parent::getIp($ip); $this-&gt;info = parent::getBrws($info); $this-&gt;filename = 'txt/trackfile.txt'; $this-&gt;fh = fopen($this-&gt;filename, 'w'); fwrite($this-&gt;fh, $this-&gt;hostnm . '\r\n'); fwrite($this-&gt;fh, $this-&gt;ip . '\r\n'); fwrite($this-&gt;fh, $this-&gt;info . '\r\n'); fwrite($this-&gt;fh, '--------------------' . '\r\n'); fclose($this-&gt;fh); } } $track2 = new trackem2file(); $track2-&gt;wrtInfo(); ?&gt; </code></pre> <p>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.</p> <p>Thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload