What happens if you call a constructor from a dest

2019-03-07 04:51发布

Calling __construct() function from __destruct(),

<?php

public function __construct() {
    echo "Hi";
}

public function __destruct() {
    $this->__construct();
}

?>

will it create infinite loop?

2条回答
老娘就宠你
2楼-- · 2019-03-07 05:04

No, it won't. __construct is just regular function while called directly instead of using new ClassName;

查看更多
\"骚年 ilove
3楼-- · 2019-03-07 05:11

No, but this will:

class Test {

    public function __construct() {
        echo "Hi";
    }

    public function __destruct() {
         new Test();
    }

}

new Test();

Example: http://ideone.com/94XUg

查看更多
登录 后发表回答