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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:32:22+00:00 2026-06-04T03:32:22+00:00

I recently read an article on Wikipedia about Design Pattern So far I’ve done

  • 0

I recently read an article on Wikipedia about Design Pattern

So far I’ve done this, but it returns Fatal error: Maximum function nesting level of '100' reached, aborting!

Logically I know, it will return nesting error, But, I don’t understand how is the best step.

class Main {
    $this->Aa = new Aa;
    $this->Bb = new Bb;
    $this->Cc = new Cc;
    }
class Aa extends Main {
    function blahA() {
        // blah blah
        }
    function testA() {
        $ret[] = $this->blahA(); // Call inside class
        $ret[] = $this->Bb->blahB(); // Call outside class
        $ret[] = $this->Cc->blahC(); // Call outside class
        return $ret;
        }
    }
class Bb extends Main {
    function blahB() {
        // blah blah
        }
    function testB() {
        $ret[] = $this->blahB(); // Call inside class
        $ret[] = $this->Aa->blahA(); // Call outside class
        $ret[] = $this->Cc->blahC(); // Call outside class
        return $ret;
        }
    }
class Cc extends Main {
    function blahC() {
        // blah blah
        }
    function testC() {
        $ret[] = $this->blahC(); // Call inside class
        $ret[] = $this->Aa->blahA(); // Call outside class
        $ret[] = $this->Bb->blahB(); // Call outside class
        return $ret;
        }
    }

Basically i want to manage my classes design, in order the method in Aa class is also reusable in Bb class and vice versa.
I curious, how to build the relationship like my classes above, How to extends the class to get above pattern? And what is the name of this pattern? please also give me a link that i can learn from.

Many 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-04T03:32:24+00:00Added an answer on June 4, 2026 at 3:32 am

    Consider creating Aa and Bb separately and using Dependency Injection so each class will have a reference to the other. You should make sure the two classes are not too tightly coupled though.

    The Gang of Four (GoF) Design patterns book mentioned in the comments is a good one, but the Head First Design Patterns is a bit easier (also very enjoyable) for beginners.

    Here is an example. Notice there are better ways to set a property in PHP, I put a setter function just to be explicit. Refer to this question for more info.

    class Main {
        $this->Aa = new Aa;
        $this->Bb = new Bb;
        $this->Cc = new Cc;
    
        // Can use properties instead of setters
        $this->Aa->setB(Bb);
        $this->Aa->setC(Cc);
    
        $this->Bb->setA(Aa);
        $this->Bb->setC(Cc);
    
        $this->Bb->setA(Aa);
        $this->Bb->setC(Bb);
        }
    
    class Aa {                // No need to extend Main, right?
        function blahA() {
            // blah blah
            }
        // Dependency injection, Bb is now a member of this class
        // Consider doing this with PHP properties instead
        // Using setter function to be more explicit
        function setB(Bb b) {
            this->Bb = b;
            }
        // Dependency injection, Cc is now a member of this class
        // Consider doing this with PHP properties instead
        // Using setter function to be more explicit
        function setC(Cc c) {
            this->Cc = c;
            }
        function testA() {
            $ret[] = $this->blahA(); // Call inside class
            $ret[] = $this->Bb->blahB(); // Call outside class
            $ret[] = $this->Cc->blahC(); // Call outside class
            return $ret;
            }
        }
    // Class Bb ...
    // Class Cc ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently I read this Wikipedia article regarding the Dining Philosophers problem but I am
I just recently heard of duck typing and I read the Wikipedia article about
I recently read this article Safe Thread Synchronization as I was curious about the
I`ve recently read this article about a user losing data on EC2 when dealing
I recently read an article talking about the Java annotations, and on this latter
I recently read an article about c#-5 and new & nice asynchronous programming features
Recently i read an article is about prevent brute-force attack. It said that automatically
Recently, I read this article: http://download.oracle.com/javase/tutorial/extra/generics/wildcards.html My question is, instead of creating a method
I have recently read the safe bool idiom article. I had seen this technique
I read this article recently , and I tried overriding the libc printf function

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.