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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:20:25+00:00 2026-05-16T05:20:25+00:00

I think my title about says it all. During the __construct() -tion of $classA

  • 0

I think my title about says it all. During the __construct()-tion of $classA, $classB is instantiated. When $classB is instantiated it needs to access to another class inside $classA (i.e. $classA->classC). $classC has already been instantiated in $classA.

Inside the __construct() function of $classB I am attempting to do something like Global $classA; so that I can get something from $classA->classC->method(). Obviously $classA hasn’t completed instantiation yet so it isn’t available to be imported from the Global scope.

What I have done to work around not being able to access $classA via Global is to pass $this as an argument to $classB when it is instantiated in $classA. This is messy but it works. I would like to try to avoid the messy-ness and hackish feel of passing $this.

Does anyone have any ideas how to better accomplish what I am trying to do?

I know that this is kind of complex so if anyone has any ideas how I could clarify it I will be happy to oblige!

  • 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-16T05:20:26+00:00Added an answer on May 16, 2026 at 5:20 am

    Actually, I would say that passing $this to ClassB is fine – I think it’s a totally reasonable way to recursively nest class instances.

    More importantly, is there a reason you are nesting recursively like this? If you could reorganize the classes to not depend on one another in this way at construction, you could simplify the whole problem.

    (I can’t really say for sure without seeing code, and I’m not 100% sure I understand the problem)

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

Sidebar

Related Questions

I think the title pretty much says it all... I'm looking to implement an
I think the title says it, as well...but of course some more explanation assume
OK, I don't think the title says it right... but here goes: I have
Sorry about the title, I couldn't think of a better way to describe the
I think title should be good enough.
OK so that title sucks a little but I could not think of anything
I'm sorry I could not think of a better title. The problem is the
Sorry for the bad title, but I couldn't think of a better one. I'm
Sorry for the slightly rubbish title. I could not think how to describe this
Is it possible to set some image as title of Navigation bar? I think

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.