php destructor behaviour

前端 未结 5 1670
一个人的身影
一个人的身影 2020-12-16 00:23

im trying to understand php constructor and destructor behaviour. Everything goes as expected with the constructor but i am having trouble getting the destructor to fire imp

5条回答
  •  太阳男子
    2020-12-16 01:11

    Method __destruct() is usless. Is better to do something like this:

    class MyClass {
        function __construct() {
            register_shutdown_function([
                &$this,
                'the_end_game'
            ]);
        }
    
        function the_end_game() {
            /* Your last part of code, save logs or what you want */
        }
    }
    

提交回复
热议问题