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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:34:58+00:00 2026-06-15T07:34:58+00:00

From a random php.net post : If you are doing $whatever = null; then

  • 0

From a random php.net post:

If you are doing $whatever = null; then you are rewriting variable’s
data. You might get memory freed / shrunk faster, but it may steal CPU
cycles from the code that truly needs them sooner, resulting in a
longer overall execution time.

Apparently this is the undisputed truth so maybe someone would be so kind as to explain.

I mean, what, does unset magically not execute any assembly instructions whereas $whatever = null; does? The answer, as given, is about as useful as saying

$whatever = null resets the buffer and the L1 cache whereas unset clears the buffer and resets the L2 cache.

Techno mumbo jumbo doesn’t constitute an answer.

  • 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-15T07:34:59+00:00Added an answer on June 15, 2026 at 7:34 am

    An important difference between both methods is that unset($a) also removes $a from the symbol table; for example:

    $a = str_repeat('hello world ', 100);
    unset($a);
    var_dump($a);
    

    Outputs:

    Notice: Undefined variable: a in xxx
    NULL
    

    But when $a = null is used:

    $a = str_repeat('hello world ', 100);
    $a = null;
    var_dump($a);
    

    Outputs:

    NULL
    

    I ran the code through a benchmark as well and found that $a = null is roughly 6% faster than its unset() counterpart. It seems that updating a symbol table entry is faster than removing it.

    Addendum

    The other difference (as seen in this small script) seems to be how much memory is restored after each call:

    echo memory_get_usage(), PHP_EOL;
    $a = str_repeat('hello world ', 100);
    echo memory_get_usage(), PHP_EOL;
    // EITHER unset($a); OR $a = null;
    echo memory_get_usage(), PHP_EOL;
    

    When using unset() all but 64 bytes of memory are given back, whereas $a = null; frees all but 272 bytes of memory. I don’t have enough knowledge to know why there’s a 208 bytes difference between both methods, but it’s a difference nonetheless.

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

Sidebar

Related Questions

I get a random row from a mysql-server using php. I then display some
Suppose I am echoing random data from PHP to browser. Total amount of random
I randomly get a row from a mysql-database using php (ugly random, I know).
I have a lost of sentences generated from http://www.ywing.net/graphicspaper.php , a random computer graphics
I would pick a random line from Memo1 and then run it as a
A PHP function I am writing pulls a small bit of HTML data from
How can I regenerate random decimal from -0.0010 to 0.0010 with php rand() or
How do I get a random post in Wordpress? I would like to display
I recently started development in ASP.NET, and coming from a PHP background I sprinkle
Could someone help me understand how to preload the images from random.php page so

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.