Re: late static binding php6

php.internals

Mike Lively

18 years ago
Stanislav Malyshev wrote:
>> I realize that instance calls are a completely different ball game than >> static calls but LSB was supposed to give us the same flexibility. > > Actually, I don't think it was. If you want objects, why not use the > real thing? LSB was created to solve just one particular problem - > inability to distinguish A::method() from B::method() if B extends A.
Being one of the original people requesting this I would have to say that you aren't completely accurate in that statement. That may have been the goals of the most recent patch's collaborators but it certainly wasn't mine. The reason I originally wanted it was because the way statics were originally implemented was too rigid to do things that I wanted to with them. LSB was a way to provide a flexible inheritance model for static classes. This would allow for the framework creator's dream of not having to instantiate objects for the sole purpose of instantiating new objects: $model = new Author(); $more_models = $model->findByName('Mike'); Instead you could place your 'factory' code into a base class as a static and extend it appropriately. This goal was met, but with yet another severe limitation in that you lose the ability to reimplement after you extend. In my opinion this is foundational to object oriented design and I know that alot of people agree with me. So in that vain what's wrong with going the full length on a new feature that isn't set in stone?
> >> called class on. It would allow more complex forms of inheritanc > "more complex" is not always better.
Rest assured that this is not the bad kind of 'more complex' I believe that with a large number of OO programmers this is going to be more natural. Bear in mind that this patch is in a large part geared to please those people that though self:: should have referred to the calling class to begin with. I can all but guarantee that you will be hearing the same arguments about 'parent::' within a fairly short amount of time after 5.3 goes out. Maybe then we will talk about 'Later Static Binding' :P.

Stanislav Malyshev

18 years ago
> Rest assured that this is not the bad kind of 'more complex' I believe
I'm afraid I must disagree. The feature that was missing was to know the true calling class name. That was implemented. You can build from it, there's no need to add further complication to the language. You can easily find out the calling class for static call, you can easily find it's parent, provided one exists, you can easily call any method of this class.
-- Stanislav Malyshev, Zend Software Architect stas@zend.com http://www.zend.com/ (408)253-8829 MSN: stas@zend.com

Jochem Maas

18 years ago
Stanislav Malyshev wrote:
>> Rest assured that this is not the bad kind of 'more complex' I believe > > I'm afraid I must disagree. The feature that was missing was to know the > true calling class name. That was implemented. You can build from it, > there's no need to add further complication to the language. You can > easily find out the calling class for static call, you can easily find > it's parent, provided one exists, you can easily call any method of this > class.
class A { static function find($id) { // lets try and find a 'something' } } class B extends A {} // I'd like a 'B' please bob. $b = B::find( 1 ); are you saying that A::find() can tell that it was called as B::find() ?

Mike Lively

18 years ago
Jochem Maas wrote:
> Stanislav Malyshev wrote: > >>> Rest assured that this is not the bad kind of 'more complex' I believe >>> >> I'm afraid I must disagree. The feature that was missing was to know the >> true calling class name. That was implemented. You can build from it, >> there's no need to add further complication to the language. You can >> easily find out the calling class for static call, you can easily find >> it's parent, provided one exists, you can easily call any method of this >> class. >> > > class A { > static function find($id) { > // lets try and find a 'something' > } > } > > class B extends A {} > > // I'd like a 'B' please bob. > $b = B::find( 1 ); > > > > are you saying that A::find() can tell that it was called as B::find() ? >
No, your example would work. WHere it breaks down is if you want to specialize B::find(); class B extends A { static function find($id) { /* do something special */ parent::find($id); } } in that situation A::find(); would not be able to know it was being called by B::find() because parent:: is considered an explicit class name reference.

Stanislav Malyshev

18 years ago
> in that situation A::find(); would not be able to know it was being > called by B::find() because parent:: is considered an explicit class > name reference.
It will be, just not by means of parent::.
-- Stanislav Malyshev, Zend Software Architect stas@zend.com http://www.zend.com/ (408)253-8829 MSN: stas@zend.com

Stanislav Malyshev

18 years ago
> class A { > static function find($id) { > // lets try and find a 'something' > } > } > > class B extends A {} > > // I'd like a 'B' please bob. > $b = B::find( 1 ); > > > > are you saying that A::find() can tell that it was called as B::find() ?
Yes, this is exactly what LSB does.
-- Stanislav Malyshev, Zend Software Architect stas@zend.com http://www.zend.com/ (408)253-8829 MSN: stas@zend.com