After reading this description of late static binding (LSB) I see pretty clearly what is going on. Now, under which sorts of circumstances might that be most useful or neede
If you need to access an overloaded static property/Method within a method that hasn't been overloaded in a subclass - you need late static binding. A quick example: paste2.org
The classic example is the ActiveRecord class from Rails, if you try to implement something similar in PHP, which would look like this: class User extends ActiveRecord
and then try to call User::find(1)
the method that gets called is actually ActiveRecord::find()
because you haven't overloaded find()
in User
- but without late static binding the find()
method in ActiveRecord
has no way of knowing which classed it got called from (self
within it will always point to ActiveRecord
), and thus it can't fetch your User-object for you.