<?php #> 5.4
class foo{
static function newFoo( Closure $foo ){
$foo = $foo->bindTo( null,__CLASS__ );
return $foo;
}
static function parentFoo(){
return get_called_class();
}
}
$foo = foo::newFoo( function( $foo ){ echo "Hello, $foo! My name is ".static::parentFoo(); } );
$foo( 'Foo' );
edit
or...
<?php #> 5.4
class foo{
static function newFoo( Closure $foo ){
$foo = $foo->bindTo( null,__CLASS__ );
return $foo;
}
static function parentFoo(){
return get_called_class();
}
}
$foo = foo::newFoo( function()use( &$bar ){ echo "Hello, $bar! My name is ".static::parentFoo(); } );
$bar = 'Me';
$foo();
$bar = 'You';
$foo();