Reputation: 4249
I am just starting with Anonymous functions namely Closures and I've run into an issue. I am using the Closure to call a static function inside a class called Project to return a value in another class called Application. Below is a simplified version of my problem
class Project{
public function __construct(){
self::ProcessParams(function() {
return Application::return_param('1');
}, 'param2', 'param3');
}
}
public static function ProcessParams($param1, $param2, $param3){
var_dump($param1);
}
}
My problem is the var_dump() in the ProcessParams function doesn't return the requested value but rather inserts the whole Project class into $param1
object(Closure)#90 (1) { ["this"]=> object(Project)#34 (3) { ..... }
What am I doing wrong??
Thanks
Upvotes: 1
Views: 836
Reputation: 158100
You need to call the closure in order to retrieve it's return value:
var_dump($param1());
You can start here to learn more about anonymous functions: http://php.net/manual/de/functions.anonymous.php
Upvotes: 3