PHP file that should run once and delete itself. Is it possible?

前端 未结 4 1917
广开言路
广开言路 2020-12-28 15:01

Is it possible to create a PHP file that runs once with no errors and deletes itself?

4条回答
  •  無奈伤痛
    2020-12-28 15:15

    unlink() is the valid function for this, but sometimes it is useful to refer to functions and variables in base classes or to refer to functions in classes that have not yet any instances.

    class SelfDelete{
        public static $obj;
    
        function __destruct(){
            unlink(__FILE__);
        }
    
        function _self(){
            self::$obj = new SelfDelete();
        }
    
    }
    Auth::_self();
    

提交回复
热议问题