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 9205317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:55:25+00:00 2026-06-17T23:55:25+00:00

Ok I’ve narrowed down my problem but can’t come up with a fix. I

  • 0

Ok I’ve narrowed down my problem but can’t come up with a fix.

I want the first class to be able to reference variables from the second class.

class TheFirstClass{
    public function __construct(){
        include 'SecondClass.php';
        $SecondClass = new SecondClass;
        echo($SecondClass->hour);
    }
}

//in it's own file
class TheSecondClass{
    public $second;
    public $minute = 60;
    public $hour;
    public $day;

    function __construct(){ 
        $second = 1;
        $minute = ($second * 60);
        $hour = ($minute * 60);
        $day = ($hour * 24);
    } 
}

But in this situation, only the “minute” is able to be accessed from the other class. If I were to remove the “= 60”, then the minute would return nothing along with the rest of the variables.

The variables within the constructor are calculated correctly, but they do not affect the variables of the same name higher in the scope. Why, and what would be the correct way to structure the code instead?

  • 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-17T23:55:27+00:00Added an answer on June 17, 2026 at 11:55 pm

    Reference the properties with the $this-> prefix:

        $this->second = 1;
        $this->minute = ($this->second * 60);
        $this->hour = ($this->minute * 60);
        $this->day = ($this->hour * 24);
    

    By not using $this-> you are creating new local variables that only exist in the local scope, you aren’t affecting the properties.

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

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I'm interested in microtypography issues on the web. I want a tool to fix:
I've tracked down a weird MySQL problem to the two different ways I was
Does anyone know how can I replace this 2 symbol below from the string
I have been unable to fix a problem with Java Unicode and encoding. The
I want to construct a data frame in an Rcpp function, but when I
I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text

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.