On Apr 29, 2008, at 3:15 AM, Sebastian Bergmann wrote:
John Carter -X (johncart - PolicyApp Ltd at Cisco) schrieb:
could you explain why Interfaces can't have properties
Because interfaces are implemented which makes no sense for
attributes.
Sebastian,
This is true for the data storage representation of a property.
But, when you add the possibility of getters and setters, a property
becomes an abstraction. It would make sense that an interface
declares abstractly that a property will be available while leaving it
up to a class to implement it. Whether the implementation would be
through a instance variable or through accessor methods is an
implementation detail. This is known as the uniform access principle.
http://en.wikipedia.org/wiki/Uniform_access_principle
However, right now, we only have the virtual or "missing property"
technique of defining accessors with __get and __set, rather than a
structural syntax that could be used to verify interface
implementations. (The structural way could also offer better
reflection, better performance, differing visibility for getters and
setters, etc.)
Properties in interfaces make no sense now, but if we ever get a
structural method of declaring getters and setters, they might make
sense.
Best Regards,
Jeff
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php