3 ms·
Closure::bindTo gives a nice js-like feeling, but i wonder why the hell a invocation of a closure in a class member triggers a warning.
by zombielifestyle 15y ago
Closure::bindTo gives a nice js-like feeling, but i wonder why the hell a invocation of a closure in a class member triggers a warning.
- TomNomNom 15y agoClass/object members and methods do not share a "namespace", so it's possible to have a method and a member with the same name. If you assigned a closure to a member that had a colliding method, PHP wouldn't know which one to execute. I'm guessing this is at least some of the reason for that behaviour. You can force it to work in the absence of a collision by using a __call override. An example of which can be seen here: https://github.com/TomNomNom/Talk---New-stuff-in-PHP-5.4/blob/master/10-mungeable-objects.php https://github.com/TomNomNom/Talk---New-stuff-in-PHP-5.4/blo...
- zombielifestyle 15y agoDidn't think of that, pretty obvious now. ty :)