class A{}
class B{}
$a = function (){
$a = new A();
var_dump($a);
return $a;
};
var_dump($a);
$b = $a(new B());
var_dump($b);
<strong>
输出:object(Closure)#1 (0) { }
object(A)#3 (0) { }
object(A)#3 (0) { }
</strong>
class A{}
class C{}
class B{
public function run(){
$b = function (){
return new A();
};
var_dump($b);
var_dump($this);
return $b(new C());
}
}
$b = new B();
var_dump($b->run());
输出:object(Closure)#2 (1) { ["this"]=> object(B)#1 (0) { } }
object(B)#1 (0) { }
object(A)#4 (0) { }
My question is, does passing in any object convert the closure object into the original object? Why is this happening?
I am at /a/11... and I wonder why the original object can be retrieved by passing in ($this).
Just take the first code segment as an example.
Are you wondering why the B object passed in completely disappeared when printed and turned into an A object?
Because although you
$a(new B());
了,但是匿名函数没接收啊,所以内部还是直接new A();
Execute this code and get a feel for it:
$b(new C()) Your anonymous function $b does not accept parameters