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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:04:06+00:00 2026-06-07T08:04:06+00:00

Reading the Google Developers PHP performance tips I saw that it isn’t recommended to

  • 0

Reading the Google Developers PHP performance tips I saw that it isn’t recommended to make an extra copy of a varible.

Instead of this:

$description = strip_tags($_POST['description']);
echo $description;

It recommends this:

echo strip_tags($_POST['description']);

The reason is a possible unnecessary consumption of memory.

But doing some searches I saw some rebuttals saing that PHP implements “copy-on-write” memory management. This basically means that we can assign a value to as many variables as we like without having to worry about the data actually being copied.

So I would like to know if in more complex situations, where for example $_POST or $_GET variables will be used in many places of the code, whether it is better practice to use or not use extra variables, considering these criteria:

1) Security

2) Maintenance / Readability

3) Performance

EDIT 1

I will use the below example to better ilustrate the question.

Is it better this kind code (Considering the criteria above):

$user = anti_injection($_POST['user']);
$pass = anti_injection($_POST['pass']);

// Continue the code using $user and $pass

Or this?

$_POST['user'] = anti_injection($_POST['user']);
$_POST['pass'] = anti_injection($_POST['pass']);

// Continue the code using $_POST['user'] and $_POST['pass']
  • 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-07T08:04:08+00:00Added an answer on June 7, 2026 at 8:04 am

    PHP’s “lazy copy” only applies to arrays. The array’s data is only duplicated if one copy of the array is changed, which is why it’s okay for the foreach loop to work on a copy of the original array, for instance.

    Objects are passed by reference, even when not told to do so with &. Example:

    $a = new StdClass();
    $b = $a;
    $b->derp = "foo";
    var_dump($a->derp); // "foo"
    

    Resources are references to a resource to be used by a particular extension, so they can’t meaningfully be copied.

    Everything else is copied directly.


    Unnecessary variables should be avoided anyway. For instance, instead of:

    $step1 = 123;
    $step2 = $step1 * 4;
    $step3 = $step2 + 99;
    $step4 = $step3 / 3;
    echo $step4;
    

    You could just write:

    echo (123*4+99)/3;
    

    (or, in this case, just echo 197;)

    The point is, unnexessary variables do create clutter and could potentially conflict with a variable you defined elsewhere.

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

Sidebar

Related Questions

I have been reading about making ajax heavy applications more search engine friendly: https://developers.google.com/webmasters/ajax-crawling/docs/getting-started
I know from reading the assoc. Google group that there is not currently an
two question for you: reading google documentation i've make an html with the JS
reading this https://developers.google.com/in-app-payments/docs/tutorial Quoted from the above page: Because you sign the JWT using
I was reading in google's documentation their new pagespeed plugin, that they recommend using
I was reading the Google Developers documentation, and I was not able to find
I was reading this excellent article on V8, Google's Javascript engine: https://developers.google.com/v8/design#mach_code . At
I've been reading https://developers.google.com/maps/documentation/javascript/overlays for a while now and I can't seem to get
I was reading the documentation for the range object on developers.google.com. For the function
when reading a python ndb api of google app engine, I cam across this

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.