Wednesday, 18 September 2013

Anonymous function in class php 5.3

Anonymous function in class php 5.3

I searched a lot and try to understand the way anonymous function work.
I found that we can use $seft = $this and then use it inside anonymous
function.
But what I can't understand is:
May I have ?
class A
{
function __Construct()
{
$self = new B;
$self->helloworld = function($world,$self) {
echo get_class($self).' '.$world;
};
}
}
class B
{
function __Construct()
{
$this->helloworld('want to say hello world!');
}
}
$A = new $A;
//Ouput B want to say hello world!
Or there're other ways to work around this?

No comments:

Post a Comment