|
Posted by Vince Morgan on 04/23/07 12:43
"Steve" <no.one@example.com> wrote in message
news:VRNWh.43$Pi6.30@newsfe04.lga...
>
> "Vince Morgan" <vinhar@REMOVEoptusnet.com.au> wrote in message
> news:462b2b63$0$16552$afc38c87@news.optusnet.com.au...
> |
> | "Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
> | news:PI-dnRXMkqxCwLTbnZ2dnUVZ_qupnZ2d@comcast.com...
> | > Vince Morgan wrote:
> | > > "Steve" <no.one@example.com> wrote in message
> | > > news:zGbWh.1456$go5.566@newsfe12.lga...
> | > > You are undoubtedly aware that this has to be the most misunderstood
> | > > behaviour in all of php. Perhaps in all programing in all
languages!!
> | The
> | > > number of posts I've read in the last few hours that clearly
> | misunderstand
> | > > _set() and __get() is astonishing! And all I've gleened from them
was
> | > > further misunderstanding. Cant blame them realy. You have been
trying
> | to
> | > > hammer the point home but the nails have just kept bending. I don't
> | think
> | > > I've ever been so confused about anything in my life.
> | > > Thank you!!
> | > > You have my undying grattitude Steve! :)))
> | > > Vince
> | > >
> | > >
> | >
> | > Vince,
> | >
> | > It's probably misunderstood because it's pretty much a violation of OO
> | > principles. OO principles indicate you can set and get values - but
> | > that you have separate setter and getter functions for these.
> | >
> | > Now you can emulate this in other OO languages such as Java, C++ and
> | > SmallTalk. But it's pretty much frowned upon. Experienced
programmers
> | > in these languages pretty much follow the defacto standard to have
> | > separate getter and setter functions of each value you want to be able
> | > to change/retrieve.
> | >
> | > Doing it other ways just gets into too much of a hassle.
> | >
> | > Now PHP has tried to implement something which really is against OO
> | > principles (so what's new here?).
> | >
> | > I've looked at it - but I really don't find it useful. This style is
> | > not implemented in other languages for very good reason - it really
> | > complicates the code, just as these functions do in PHP.
> | >
> |
> | I know I don't have to tell you that it certainly confused me. I was
> quite
> | stunned when I first saw that you could add methods to a js object.
> | However, as you don't have access to the source of those classes I can
> | understand why some consider it a whorthwhile feature.
> | However, in the case of php where you do have such access it seems
> ludicrous
> | to me to do such a thing. If someone wants to add additional
> functionality
> | to a php object, why not simply write it into the class? Treating them
as
> | if they are compiled objects seems more than a little silly to me.
>
> oh you do have access to the source of those classes. you can
document.write
> an entire js class if you wanted to...using alert none-the-less. even make
a
> prototype and forget whether the rhs assignment for a function should be
> just the name or the name plus () ? figure out which is which and you've
now
> hacked how to get the source of custom objects.
>
> as for php, you can just as easily make properties and functions and put
> them into a custom class that you didn't author. __set/__get would help
> prevent this...if you threw errors in your object to detect when this was
> attempted.
>
> it doesn't matter, to me, whether php objects are compiled or scripted.
what
> should be important is that objects are able to maintain their
encapsulation
> (if the author chooses to enforce it)...which is what __set/__get does.
what
> php is lacking is the default ability to assign private getters/setters to
> properties such that:
>
> $foo->bar = 'hello world';
>
> would trigger bar's setter in your object's code. this is present in may
> scripted languages and manditory for compiled languages like object c,
c++,
> c#, vb/.net, etc.
>
> but anywho. :)
>
I agree. I can't see anything bad with being able to implement private
getters that are called in the fashion you've just described Steve.
In fact it is very attractive to me. I implement operator overloads in C++
as often as practical, and your proposed usage can emulate that to some
degree. In fact I was a little disapointed when I first looked at php that
it didn't have operator overloading.
[Back to original message]
|