Re: Class Properties in Interfaces?

From: Date: Wed, 30 Apr 2008 06:51:26 +0000
Subject: Re: Class Properties in Interfaces?
References: 1 2 3 4 5 6 7 8 9 10 11 12 13  Groups: php.internals 
Request: Send a blank email to internals+get-37335@lists.php.net to get a copy of this message
On Tue, 2008-04-29 at 23:37 -0700, Stanislav Malyshev wrote: > > $hair = new Hair(); > > $hair->colour = 'brown'; > > You can do this without pre-defining any properties. yes but the following (as I'm you certainly know): echo $hair->colour generates an E_NOTICE if the property isn't defined. > > The above is a much less wordy way of doing the following: > > No, it is not the same. You can override what happens when you do > setColor - like send notification to some other object or set also > matching color for the shoes, etc. :) but you can't have any behavior > attached to setting value. But it is the same... I can override the behaviour in magic get/set methods if I want. But the point is not necessarily to override, only to ensure the property is defined by all users of the interface. One approach (the getter/setter approach) is more versatile downstream (in the possibly unlikely event that the semantics for the property need to change), the other approach is more efficient. > > This is a feature of a dynamic language, not a flaw in my argument. And > > Not having rigid definitions of properties is also a feature of dynamic > language ;) There's nothing rigid about what Jeremy proposed. He just asked why properties can't be part of an interface definition. I don't see why not, I've shown the equivalence of properties to getter/setter methods (in simple usage case anyways), and so I've argued the point. It's not a particularly necessary feature for me, but that doesn't negate his original question as to why they couldn't be supported. Anyways, I'll stop being noisy on the list now. Nothing more to add :) Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP

« previous php.internals (#37335) next »