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

  • Home
  • SEARCH
  • 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 538207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:00:26+00:00 2026-05-13T10:00:26+00:00

here is my code…. class line{ function db($host, $user, $pass, $db){ mysql_connect($host, $user, $pass)

  • 0

here is my code….

class line{
    function db($host, $user, $pass, $db){
        mysql_connect($host, $user, $pass) or die("Could Not Connect to Database or Database Does not Exists....");
        mysql_select_db($db) or die("Database Does not Exists....");
    }

    $idletime = 300;
    $deltime = 600;

     function test(){
    echo $idletime;
    echo idletime;
}

}

and calling this class as

$w = new line();
$w->test();

but it says

Undefined variable: idletime in *****

please let me know what acutally the problem is…

  • 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-05-13T10:00:26+00:00Added an answer on May 13, 2026 at 10:00 am

    Your variable is a class property — or, at least, I’m guessing that’s what you want it to be…

    This line inside your test method :

    echo $idletime;
    

    Is trying to access a variable defined inside that method — not a class property.

    And there is no such local variable — hence the notice.

    To access a class property, you need to use $this, this way :

    echo $this->idletime;
    

    Also, your code is not valid : you have to declare that your “variables” are indeed class properties — i.e., you need to use some of the visibility keywords in front of them.

    Here’s you class, once re-written :

    class line {
        function db($host, $user, $pass, $db) {
            mysql_connect($host, $user, $pass) or die("Could Not Connect to Database or Database Does not Exists....");
            mysql_select_db($db) or die("Database Does not Exists....");
        }
    
        protected $idletime = 300;
        protected $deltime = 600;
    
        public function test(){
            echo $this->idletime;
        }
    }
    

    I have :

    • Set your properties as protected
    • And I’m using $this to access them from inside the test method
    • I have also indicated the test method is public — it’s the default, but I like being explicit about it.

    Don’t hesitate to spend some time reading the Classes and Objects section of the manual : you’ll learn lots of useful stuff 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 264k
  • Answers 264k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Have you tried: DBNull.Value May 13, 2026 at 12:15 pm
  • Editorial Team
    Editorial Team added an answer TortoiseSVN has subversion within it. Lets say you want to… May 13, 2026 at 12:15 pm
  • Editorial Team
    Editorial Team added an answer Putting interfaces in a separate library is often a good… May 13, 2026 at 12:15 pm

Related Questions

Here is my code, which takes two version identifiers in the form 1, 5,
Here is my code: ThreadStart threadStart = controller.OpenFile; Thread thread = new Thread(threadStart); thread.Start();
Here is my code: records_hash = records[:id].inject({}) { |result,h| if result.has_key?(h) result[h] += 1
Here is my code: # hi.ps1 function fun { Write-Host $args } Write-Host '---------------'
Here is my code: Event.observe(window, 'load', function() { Event.observe('form_post', 'submit', function(){ new Ajax.Updater('Posts', 'getPosts.php',

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.