Home  >  Article  >  Backend Development  >  Small example of php destructor

Small example of php destructor

WBOY
WBOYOriginal
2016-07-25 08:53:511040browse
  1. function __destruct(){
  2. /* class initialization code */
  3. }
Copy code

The destructor is automatically called by the system and cannot take parameters.

Example:

  1. class des{
  2. function __destruct(){
  3. echo "Run ends, execute destructor";
  4. }
  5. }
  6. $p=new des(); /* Instantiate class */
  7. $sum=0;
  8. for($i=0;$i<10;$i++){
  9. $sum=$sum+$i;
  10. echo $sum ."
    ";
  11. }
  12. ? >
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn