Calling __construct() function from __destruct(),
<?php
public function __construct() {
echo "Hi";
}
public function __destruct() {
$this->__construct();
}
?>
will it create infinite loop?
No, but this will:
class Test {
public function __construct() {
echo "Hi";
}
public function __destruct() {
new Test();
}
}
new Test();
Example: http://ideone.com/94XUg
No, it won't. __construct
is just regular function while called directly instead of using new ClassName;
来源:https://stackoverflow.com/questions/10384836/what-happens-if-you-call-a-constructor-from-a-destructor