Hacker News new | ask | show | jobs
by zombielifestyle 5292 days 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.
1 comments

Class/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/blo...

Didn't think of that, pretty obvious now. ty :)