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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:17:49+00:00 2026-05-15T18:17:49+00:00

I just read about unset variable through php manual. The php manual says unset()

  • 0

I just read about unset variable through php manual.

The php manual says
“unset() destroys the specified variables”

This def seems perfect until I came across static variable…
“If a static variable is unset() inside of a function, unset() destroys the variable only in the context of the rest of a function. Following calls will restore the previous value of a variable. “

This definition doesn’t seems a good one for me, at least, since “destroy the variable” implies that the variable is no longer associated with that memory location.

Does anyone else think a better definition would be “unset() makes the variable out of current scope”? I mean, rather than pointing towards lifetime, it’s better to use word scope here?

  • 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-15T18:17:50+00:00Added an answer on May 15, 2026 at 6:17 pm

    Let’s consider the function:

    function foo() {
        static $bar;
        $bar++;
        unset($bar);
    }
    foo(); //static $bar is 1
    foo(); //static $bar is 2
    

    The function compiles to:

    function name:  foo
    number of ops:  11
    compiled vars:  !0 = $bar
    line     # *  op                           fetch          ext  return  operands
    ---------------------------------------------------------------------------------
       2     0  >   EXT_NOP                                                  
       4     1      EXT_STMT                                                 
             2      FETCH_W                      static              $0      'bar'
             3      ASSIGN_REF                                               !0, $0
       5     4      EXT_STMT                                                 
             5      POST_INC                                         ~1      !0
             6      FREE                                                     ~1
       6     7      EXT_STMT                                                 
             8      UNSET_VAR                                                !0
       7     9      EXT_STMT                                                 
            10    > RETURN                                                   null
    

    A variable actually exists outside each function call to foo() and, on each call, it’s fetched and a reference to it is assigned to $bar. In fact, it’s very similar to this:

    function foo() {
        global $bar;
        $bar++;
        unset($bar);
    }
    

    When you call unset(), you’re only destroying the reference you created, not the underlying value.

    I didn’t confirm, but what I’d guess that happens is this:

    • The underlying representation of the variabe (the zval) is stored so that its reference count is 1.
    • When foo() is called, the symbol $bar is associated with this zval, its reference count is increased to 2 and the reference flag is set.
    • When unset is called, the zval has its reference count decreased to 1, the reference flag is probably cleared and the symbol $bar is removed.

    See reference count basics.

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

Sidebar

Related Questions

I just read this post about why new-line warnings exist, but to be honest
I just started to read about this new technology... Does someone have some knowledge
Just finished read this post by Greg Young, where he is talking about Microsoft
I just read about HTML 5's WebSocket interface. How can I start trying this?
I just read this article about the Entity Framework 4 (actually version 2). Entity
I just got Delphi 2009 and have previously read some articles about modifications that
I just read about mysql's SQL_CALC_FOUND_ROWS and FOUND_ROWS() which helps you get the total
I just read about the breadth-first search algorithm in the Introduction to Algorithms book
I just read about zip bombs , i.e. zip files that contain very large
I just read up on a performance of LINQ, and there is a HUGE

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.