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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:02:06+00:00 2026-05-27T23:02:06+00:00

I am getting the following error when using the code below the error. can

  • 0

I am getting the following error when using the code below the error.
can you tell me what i am doing wrong?

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes) in D:\dev\TESTCASE_classes_layout\main.class.php on line 18

Here is the code I use :

<?php

include('test_class1.php');
include('test_class2.php');
include('test_class3.php');

class Main_Class{

    protected $test_class1;   
    protected $test_class2;
    protected $test_class3;

    private $objects_array = array();


    public function Main_Class(){

        $this->test_class1 = new Test_Class1();
        $this->objects_array['test_class1'] = $this->test_class1; 
        $this->test_class2 = new Test_Class2();
        $this->objects_array['test_class2'] = $this->test_class2;
        $this->test_class3 = new Test_Class3();
        $this->objects_array['test_class3'] = $this->test_class3;

    }

    public function get_Objects(){

        return $this->objects_array;

    }

}

?>

Here is the code I use for all three test classes. It is exactly the same code only for class name number and the function name number.

<?php

class Test_Class1 extends Main_Class{

    function test1(){
        return 'hello';
    }

}

?>

It has to do with the extending part. Cause when I delete the extending part it works.

Here is my goal:

I am trying to instantiate the classes in this class and extend from it so all classes can call each other without generating another instance of the class.

maybe there is a better way of doing that so if you know that then let me know.

  • 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-27T23:02:07+00:00Added an answer on May 27, 2026 at 11:02 pm

    A constructor is called everytime you create an object of type Main_Class, or one of its subclasses.

    Since you’re creating new objects of a subtype during this creation, you run into an infinite loop that ends when memory is exhausted or the memory limit is reached:

    new Main_Class()            calls ...
    Constructor of Main_Class   calls ...
    new Test_Class1()           calls ...
    Constructor of Test_Class1  calls ...
    Constructor of Main_Class   calls ...
    new Test_Class1()           calls ...
    ...
    

    Instead, you should create the objects in a static method. But even if you do, note that your goal violates the important principle of encapsulation and will lead to an extremely poor design. Instead, you probably want to have methods that operate on an arbitrary object of type Main_Class, and override the methods (i.e. have a method test in every one of these classes).

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

Sidebar

Related Questions

I am getting following error message when using Doctrine ORM in Codeigniter. ( !
I'm getting the following error in Eclipse using the Cusp plug-in: Package LISP-UNIT is
I am getting following error when I am trying to get WebResponse using WebResponse
I am getting the following error: Access denied for user 'apache'@'localhost' (using password: NO)
I'm getting the following error when trying to build my app using Team Foundation
I am getting the following error when trying to update an object using nhibernate.
I'm getting the following error when trying to run a JSP. I'm using Tomcat
Using the Venkman JavaScript debugger for Mozilla and getting the following error: XML Parsing
I'm using Visual Studio 2008 Express edition, and keep getting the following error: Cascadedisplay.h(4)
I am using the Android code below to connect to Facebook but getting the

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.