Will variable in function be destroyed after function run?
class B {
function C() {
$x = "123456";
echo "XXX".$x;
// After this function is finished, will $x be destroyed by default to save memory in PHP?
}
}
class A {
function F1() {
return new Class_B();
}
function F2() {
$this->F1()->C();
// After this function is finished, will F1 be destroyed by default to save memory and CPU in PHP?
}
}
Regarding
$x: yes, it will be subject to garbage collection afterB::C()finishes running.Regarding
$this->F1()->C(): theF1method itself won’t be destroyed, but the instance ofBreturned by it will be destroyed afterF2finishes running.