Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8844263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:26:33+00:00 2026-06-14T11:26:33+00:00

I need to pass variables found in parent class to the extended class, but

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:26:34+00:00Added an answer on June 14, 2026 at 11:26 am

    You need to use them like this, you missed out the $this->:

    $this->info;
    $this->ip;
    $this->hostnm;
    

    Try this:

    <?php
    class trackem
    {
        public $hostnm;
        public $ip;
        public $info;
    
        public function __construct()
        {
        }
    
        public function getNm()
        {
            $this->hostnm = gethostbyaddr($_SERVER['REMOTE_ADDR']);
        }
        public function getIp()
        {
            $this->ip = $_SERVER['SERVER_ADDR'];
        }
        public function getBrws()
        {
            $this->info = get_browser(null, true);
        }
    
    }
    
    class trackem2file extends trackem
    {
        function wrtInfo()
        {
            parent::__construct();
    
            $this->getNm();
            $this->getIp();
            $this->getBrws();
            $filename = 'txt/trackfile.txt';
    
            $fh = fopen($filename, 'w');
            fwrite($fh, $this->hostnm . '\r\n');
            fwrite($fh, $this->ip . '\r\n');
            fwrite($fh, $this->info . '\r\n');
            fwrite($fh, '--------------------' . '\r\n');
            fclose($fh);
    
        }
    }
    
    $track2 = new trackem2file();
    $track2->wrtInfo();
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to pass user_id, not logged in user, but user_id from view. I
I need to pass a variable to a javascript function,but I got a little
I need to pass along a string with my FileReference, or provide that string
I've found several questions on how to pass variables from bash into awk ,
I have a model class called VideoGame . I need the class to get
Following Bugsense docs I've found that I need to add this code on Service
I have loaded an array (recordArray) in RootViewController class which I need to pass
I need to pass a variable which is captured from client side via jquery
I need to pass a variable in dispatcher tag... for instance var google:EventName =
I am trying to call Ajax with jQuery and need to pass a variable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.