This a little hard for me to explain, but I'll try my best. I'm trying to find the best way to create an instance of a closure. Below is an example of how I am creating and accessing the closure:
$myvar->parse('var1, var2', function () { //my code }); I then loop through the strings by exploding the comma and put it into an array like so.
$array = array(); $array['var1'] = closure(); $array['var2'] = closure(); Later on in my code I use call_user_func to execute the function.
Now, the issue I'm having is that when I access $array['var1'] it calls the closure without any problem.
But when I access $array['var2'] it does nothing. I've been looking at diverse websites for a while without much luck. Do I need to use pointers (tried without success) or create a new instance of it somehow?
I currently only have access to php 5.3 on my server, so I can't use any of the awesome stuff in 5.4 :(
I'd really appreciate any feedback and advice you may have.
closure()expression - they are totally unrelated. So you could for example tell us whatvar_dump(closure());outputs.Closurethat can be passed along and assigned to variables or parameters of function calls. Originally, the implementors of the PHP language details in version 5.3 wanted to hide the fact that a closure is in fact a new type of object named Closure, but as PHP was a language related to the internet, and the internet does not allow much of a feature to be hiddern behind a certain feature, it naturally came to public awareness that the "new" callable type in 5.3 is an object of typeClosurewhich has instances.