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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:12:44+00:00 2026-06-06T19:12:44+00:00

okey so here is my structure. one.php two.php three.php one.php includes both two.php and

  • 0

okey so here is my structure.

one.php two.php three.php

one.php includes both two.php and three.php

two.php is

class two {
  function test(){  $var ='gello'; }}

three.php is

class three {
function testt(){  $var ='hello'; }}

So how could i use the $var variable of two.php in three.php ?

in one.php i can do that by

 $one = new two(); 
 $one->var;

any help would be appreciated.

Thanks

  • 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-06T19:12:45+00:00Added an answer on June 6, 2026 at 7:12 pm

    You need to define variable outiside the function

    When you write inside function, only the function know who are $var and show te correct value.

    class two {
        public $var = 'foo';
    
        function setVar($var = 'foo') {
            $this->var = $var;
        }
    }
    
    class three {
        function test() {
            $two = new two();
            echo($two->var); // Show 'foo'
    
            $two->setVar('bar');
            echo($two->var); // Show 'bar'
        }
    }
    
    // Result 'foo'
    $one = new two();
    echo($one->var);
    
    // Result 'fooz'
    $one->setVar('fooz');
    echo($one->var);
    
    // Result 'foo' and 'bar'
    $three = new three();
    $three->test();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okey, this is my problem. I have one service class where Ive managed to
Okey, here it goes. I have a block of code that repeats it self
Okey I have a class that prints the board and another class that prints
Okey dokey, I have a jQuery function that checks the height of 2 divs
Okey, so I'm working on a pathfinding program, where I would test various pathfinding
My Ajax function: function changeMultipleItemStatus(status) { var ids= getAllCheckedIds(); var comment = $('#txtComment').val(); $.ajax({
class A @@ololo = 1 end A::ololo A.new.ololo NoMethodError: undefined method `ololo' okey. I
Okey, here is my problem, im calling a bunch of different propertys named K0
I have two tables: <class name=Content table=language_content lazy=false> <composite-id> <key-property name=contentID column=contentID/> <key-property name=languageID
Okey, so this is my problem. I have a page structure saved into a

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.