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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:15:49+00:00 2026-06-13T05:15:49+00:00

This is a very basic php question : suppose I have 3 files, file1,

  • 0

This is a very basic php question : suppose I have 3 files, file1, file2, file3.

In file1 I declare a class called Object. In file2, I have a method that instantiate Object, call it $object, and call this method Method

In file2, this method looks like

public function Method(){
$object = new Object;
...
require_once(file3);
$anotherobject = new AnotherObject;
$anotherobject->method();

}

Finally, in file 3 I declare another AnotherObject. So, if I have a method ‘method’ in file3, can I refer to $object’s properties directly, or could I access ony the static method of Object ?

  • 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-13T05:15:50+00:00Added an answer on June 13, 2026 at 5:15 am

    This is not how decent OOp should be programmed. Give each class its own file. As I understand it you have 3 files with classes in them and want to use a the instantiated objects. Use Dependency Injection to construct classes that depend on each other.

    Example:

    file1.php:

    class Object
    {
       public function SomeMethod()
       {
          // do stuff
       }
    }
    

    file2.php, uses instantiated object:

    class OtherObject
    {
       private $object;
    
       public function __construct(Object $object)
       {
          $this->object = $object;
       }
    
       // now use any public method on object
       public AMethod()
       {
          $this->object->SomeMethod();
       }
    }
    

    file3.php, uses multiple instantiated objects:

    class ComplexObject
    {
       private $object;
       private $otherobject;
    
       public function __construct(Object $object, OtherObject $otherobject)
       {
          $this->object = $object;
          $this->otherobject = $otherobject;
       }
    }
    

    Tie all this together in a bootstrap file or some kind of program file:

    program.php:

    // with no autoloader present:
    include_once 'file1.php';
    include_once 'file2.php';
    include_once 'file3.php';
    
    $object = new Object();
    $otherobject = new OtherObject( $object );
    
    $complexobject = new ComplexObject( $object, $otherobject );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a very basic question...quite embarassing, but here goes: I have a Stopwatch
I have a very basic question about PHP. So, there is index.php that includes
Very basic seeming PHP question here... I have a page to which I'm already
This is very basic magento question i guess. I want to first get all
This is very basic question from programming point of view but as I am
This is a very basic question, so please bear with me. Consider the following
This is a very very basic question and I know one way is to
I know this is a basic PHP question, and I'm trying to learn the
i was wondering this is a very basic and probably stupid question. i am
I know this is a very common (and basic) question, however I've tried without

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.