PHP class destructor knowledge drip ----

  • Page is finished
  • Manually call the destructor method unset ()
  • Scenario: Disconnect the mysql
  • Under different circumstances, different timing destructor method call, the program execution in the following order
? < PHP
 class mycoach 
{ 
    public $ name = " Chen Peichang " ; 
    CONST hisage = 22 ;
     public $ Age = 22 ;
     Private $ Favorite = " like the small cauldron " ;
     public function __construct () 
    { 
        echo " on the outskirts of the small cauldron Villa passenger seat " .PHP_EOL; 
    } 
    public function __destruct () 
    { 
        echo " turn off the lights, right, Ding cauldron, today too tired to play the " .PHP_EOL; 
    } 
} 
$ cpc = new new mycoach (); 
echo " Bobo ~ Sausage and squirrels as well as small children have fun " .PHP_EOL;
 ?>

Output:

In the small cauldron of suburban villa seat passenger
have fun Bobo ~ Sausage and squirrels as well as small children
light on it, the small cauldron, play tired today

? < PHP
 class mycoach 
{ 
    public $ name = " Chen Peichang " ; 
    CONST hisage = 22 ;
     public $ Age = 22 ;
     Private $ Favorite = " like the small cauldron " ;
     public function __construct () 
    { 
        echo " on the outskirts of the small cauldron Villa passenger seat " .PHP_EOL; 
    } 
    public function __destruct () 
    { 
        echo " turn off the lights, right, Ding cauldron, today too tired to play the " .PHP_EOL; 
    } 
} 
$ cpc= New new mycoach (); 
unset ($ cpc); 
echo " Bobo ~ Sausage and squirrels as well as small children have fun " .PHP_EOL;
 ?>

Output:

Villa on the outskirts of the small passenger seat cauldron of
lights, right, Ding cauldron, today too tired to play the
Bobo ~ Sausage and squirrels as well as small children have fun

Guess you like

Origin www.cnblogs.com/saintdingspage/p/10988175.html