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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:58:57+00:00 2026-05-27T09:58:57+00:00

Because $a=’a’ allocates one byte but $b is not modified. In PHP, for the

  • 0

Because $a=’a’ allocates one byte but $b is not modified.

In PHP, for the code “$a=’a’;$b=$a;” allocates 2 units of memory or 1 unit?
how can I test it?

I can say that pseudoly like

alphahandler = new stringObj
alphahandler->insertContent('a');
variable a = alphahandler.objectHandler();

comes to b

variable b = a.getCurrentObjectHandler() 

or just like

b=a.getCurrentObject().toContent()

??

  • 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-27T09:58:58+00:00Added an answer on May 27, 2026 at 9:58 am

    How many times is memory allocated?

    $a='a';   # creates a new string value, and assigns it to $a
    $b=$a;    # assigns the SAME string value -- the one now in $a -- to $b
    

    Ignoring that both variables also take up memory (and require separate variable entries), there is only one string object created from the above code.

    That is, both variables now refer to the same value: there was no “copy” of the string created upon assignment.

    How much memory is allocated?

    There is much more memory being allocated (than say, 1 or 2 bytes): there is the memory for the object and then there is the memory for each variable.

    While this question relates to integers, similar stuff happens for strings (actually, more happens). A simple integer takes at least 72 bytes of memory. As mario suggested in a comment, this example may require upwards of 400 bytes.

    Happy coding.

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

Sidebar

Related Questions

Because source code can not be accessed by all users, I want to remove
Because of legacy data which is not available in the database but some external
Because jQuery is a widely used and mature collaborative effort, I can't help but
Because if it thread safe I can use just one instance of VTDGen for
because it will not show up as » but will show up as &raquo
Because the float data type in PHP is inaccurate, and a FLOAT in MySQL
Because of the inability to create Vectors dynamically, I'm forced to create one with
Because anyone can sign up and then log in,... and because a user isn't
because of compatibility issues, I compile my project in VS2008 in release mode, but
Because the the UISwitch is not so easy to customize i decide i wanna

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.