classSomeClass{privatestring$title='Some Class Title';}$some=newSomeClass();$closure=function(){return$this->title;};$get_title=$closure->bindTo($some,$some);echo$get_title();// Some Class Title
I think this is the idea. Very nasty, but indeed effective :-)
::bind() is the static variant of ->bindTo()
For those that want an example from the wild, checkout this NullAdapter from Symfony. It uses Closure::bind() to wrap items from the cache into CacheItem DTO's.
One more way: use Closure::bind().
Good call 😉 I'm adding it!
I think this is the idea. Very nasty, but indeed effective :-)
::bind()
is the static variant of->bindTo()
For those that want an example from the wild, checkout this NullAdapter from Symfony. It uses
Closure::bind()
to wrap items from the cache intoCacheItem
DTO's.Interesting way of breaking encapsulation 👍