My blog hasn't been updated yet. I just carved a CD for my mom. it's really hard to find. many Dance websites are still charged ....
My blog hasn't been updated yet. I just carved a CD for my mom. it's really hard to find. many Dance websites are still charged ....
Finally, we had to find the real connection of the song ..
Let's get started. I thought about it for a long time. I haven't thought about anything to write yet...
So I found a pen exam online... To research
First look at the following code
1234 |
$ Test = 'Siren'; $ abc = & $ test; unset ($ test); echo $ abc; |
What is this ?? If you follow the C memory processing mechanism ..
$ Abc points to the memory address of $ test.
If you delete the test memory, the memory pointed to by $ abc will also disappear .. then the value of $ abc is null ..
What is the result of PHP? Run the program
The result output is siren...
Oh my god! Is it wrong... Why ??
So I have to talk about unset ..
Strictly speaking, unset is not a function, but a language structure.
The main operation is to delete the symbols in the parameters from the current symbol table. for example, if you execute unset ($ a) in the global code, the symbols will be deleted from the global symbol table.
Except the symbol.
A global symbol table is a hash table. when this table is created, it provides the destructor of the items in the table.
When deleting a, the destructor will be called for the item pointed to by symbol a (here is the zval pointer, the main function of this destructor is to reduce the refcount of zval corresponding to a by 1. if the refcount is changed to 0, release this zvall.
Therefore, when we call unset, the memory space occupied by the variable may not be released. zval will be released only when the zval corresponding to this variable has no other variable pointing to it, otherwise, only the refcount minus 1 operation is performed.
Unset destroys the variable pointing to the object, instead of the object. the trigger of the _ destruct () destructor is used to reclaim the memory space of the variable and is executed when the garbage object is recycled.
Return to the code above,
Unset ($ test); although it is unset, the data stored in $ test is not deleted, but the test symbol is deleted in symbol_table. and run refcount _ gc -. the original memory also stores the original data of test, because $ abc points to the memory of test, so the final output of $ abc is equal
Output the value of the memory zone where test is located.