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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:32:58+00:00 2026-05-16T17:32:58+00:00

I am curious, if I create a class of many methods (functions as PHP

  • 0

I am curious, if I create a class of many methods (functions as PHP still call them) which many of them are not used and I create an object, does it create memory for all methods even if most methods aren’t being used? I’m doing PHP OOP coding.

  • 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-16T17:32:59+00:00Added an answer on May 16, 2026 at 5:32 pm

    Now, take this with a grain of salt because this is from memory and I can’t find my original sources, but if I remember correctly, memory is allocated by class.

    Once you have a class that’s loaded, it will have all methods loaded into memory, even if they are not being executed yet. Then if you have new instances of that class, PHP will reference the original class for methods. It will allocate it’s own memory space for members, though. Note that there is a distinction between class and instance.

    //this is a class (obviously)
    class foo {
        __construct(){
            print "constructing foo\n";
        }
        public function bar(){
            print "called bar\n";
        }
    }
    
    //this is the first instantiation of that class,
    //the class already has methods loaded in memory, ready to run.
    //bar is never called, but it's still in memory, just waiting.
    $my_foo = new foo();
    
    //this is the second instance, everything is already loaded, 
    //if you call bar, there's no need to reallocate anything.
    $your_foo = new foo();
    $your_foo->bar();
    

    The above will load the class foo which in turn loads the construct and bar methods (as well as others that are built in). Then when you instantiate it, it doesn’t need to allocate space for methods, it just references the already loaded methods. So in my example, the bar() method is already loaded and waiting, no need to reallocate space.

    Of course this gets to be a bit tricky when talking about private methods/members as well as references to instances. Suffice it to say that if you’re worried that much, then PHP may not be the language to be using.

    Not sure if there’s a way to dig into PHP code to see what memory is allocated as you would easily be able to with C, for instance. You would probably have to go that low-level in order to answer the question in your specific case.

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

Sidebar

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.