Anonymous recursive PHP functions
Is it possible to have a PHP function that is both recursive and anonymous? This is my attempt to get it to work, but it doesn’t pass in the function name.
Is it possible to have a PHP function that is both recursive and anonymous? This is my attempt to get it to work, but it doesn’t pass in the function name.
Since PHP 7.0, you can do this with ($obj->lambda)()
:
Anonymous functions are available from PHP 5.3.
Should I use them or avoid them? If so, how?
Basically I’d like to do something like this:
I want to create a client-side function that can receive and execute arbitrary commands using client-side variables. I will be sending these functions from my server by using socket.io to send a JSON object containing an anonymous function which will be my command. It looks something like the following:
I am a relative newbie to all things javascript, node.js, mocha etc.
Can anybody please help me to understand why the following code is working
Considering the following code snippet: # directorys == {'login': <object at …>, 'home': <object at …>} for d in directorys: self.command["cd " + d] = (lambda : self.root.change_directory(d)) I expect to create a dictionary of two function as following : # Expected : self.command == { "cd login": lambda: self.root.change_directory("login"), "cd home": lambda: self.root.change_directory("home") } … Read more