When will PHP class objects be destroyed? There is a problem: when the object will be destroyed automatically, and the script will be destroyed automatically after execution. However, if I create an object a in a function, when this function is executed, will object a be automatically destroyed? ------ Solution -------------------- reference: school.itzcn.comspecial-spid-30.html above explained more details PHP class object in when to destroy it?
There is a problem: when the object will be destroyed automatically, and the script will be destroyed automatically after execution. However, if I create an object a in a function, when this function is executed, will object a be automatically destroyed?
------ Solution --------------------
Refer:
Http://school.itzcn.com/special-spid-30.html
The description above is more detailed,
Hope to help the landlord.
------ Solution --------------------
To be accurate, it is recycled after the garbage collector runs .....
Normally, no problem. The function will be recycled after it is completed...
If you are interested, run this program :(
Class {
Function _ construct (){
$ This-> B = new B ($ this );
}
Function _ destruct (){
$ This-> B->__ destruct ();
}
}
Class B {
Function _ construct ($ parent = NULL ){
$ This-> parent = $ parent;
}
Function _ destruct (){
Unset ($ this-> parent );
}
}
Function test (){
For ($ I = 0; I I <10000; $ I ++ ){
$ A = new ();
// $ A->__ destruct (); // check whether this line of comment is different from that of no comment.
}
}
Test ();
Echo number_format (memory_get_usage ());
The results of the above line are completely different from those of the above line.