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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:53:27+00:00 2026-05-11T08:53:27+00:00

I realise the second one avoids the overhead of a function call ( update

  • 0

I realise the second one avoids the overhead of a function call (update, is actually a language construct), but it would be interesting to know if one is better than the other. I have been using unset() for most of my coding, but I’ve recently looked through a few respectable classes found off the net that use $var = null instead.

Is there a preferred one, and what is the reasoning?

  • 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. 2026-05-11T08:53:27+00:00Added an answer on May 11, 2026 at 8:53 am

    It was mentioned in the unset manual’s page in 2009:

    unset() does just what its name says – unset a variable. It does not force immediate memory freeing. PHP’s garbage collector will do it when it see fits – by intention as soon, as those CPU cycles aren’t needed anyway, or as late as before the script would run out of memory, whatever occurs first.

    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.

    (Since 2013, that unset man page don’t include that section anymore)

    Note that until php5.3, if you have two objects in circular reference, such as in a parent-child relationship, calling unset() on the parent object will not free the memory used for the parent reference in the child object. (Nor will the memory be freed when the parent object is garbage-collected.) (bug 33595)


    The question "difference between unset and = null" details some differences:


    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 

    It seems that $a = null is a bit faster than its unset() counterpart: updating a symbol table entry appears to be faster than removing it.


    • when you try to use a non-existent (unset) variable, an error will be triggered and the value for the variable expression will be null. (Because, what else should PHP do? Every expression needs to result in some value.)
    • A variable with null assigned to it is still a perfectly normal variable though.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 85k
  • Answers 85k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer With an XmlNamespaceManager and an alias in the xpath: XmlNamespaceManager… May 11, 2026 at 5:15 pm
  • Editorial Team
    Editorial Team added an answer You could replace the lines with a different type of… May 11, 2026 at 5:15 pm
  • Editorial Team
    Editorial Team added an answer The cause of the error is that Netbeans is incompatible… May 11, 2026 at 5:15 pm

Related Questions

I have a working WinForm that handles the search functionality in my customer database.
I have the following situation: class A { public: A(int whichFoo); int foo1(); int
I have two classes, and want to include a static instance of one class
My program has a component - dubbed the Scheduler - that lets other components

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.