Re: Class Properties in Interfaces?

From: Date: Tue, 29 Apr 2008 15:22:58 +0000
Subject: Re: Class Properties in Interfaces?
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-37296@lists.php.net to get a copy of this message
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

« previous php.internals (#37296) next »