php constructor and destructor

class Human{

    public function __construct(){ //The constructor class, once instantiated, will be called

        echo 'aaa';

    }

    public function __destruct(){ // The destructor method is called when the object is destroyed

        echo 'bbb';

    }

    public function cc(){

        echo '11111';

    }

}

$a = new Human();

$a -> cc();

?>

Then the output result is aaa11111bbb       

Execution process After the class is instantiated, the constructor is executed first, the ordinary method is executed, and the destructor method is executed


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324727882&siteId=291194637