Isn't this need basically covered by accessors?

https://wiki.php.net/rfc/propertygetsetsyntax-as-implemented

- Rasmus

On Sat, Dec 1, 2012 at 7:53 PM, <internals-digest-h...@lists.php.net> wrote:

> From: Sebastian Krebs <krebs....@gmail.com>
> To: PHP internals list <internals@lists.php.net>
> Cc:
> Date: Sat, 1 Dec 2012 13:34:58 +0100
> Subject: Abstract properties
> Hi,
>
> Don't want to start a big discussion, but is there a concrete reason, why
> abstract properties (or "a kind of abstract") are not supported? I've
> learned, that "an interface [the concept, not the implementations within a
> language] is the sum of all accessible (--> public) methods and
> properties", what as far as I understand means, that properties could (and
> should) be defineable in concrete interfaces too
>
> interface Queue {
>   public function enqueue($value);
>   public function dequeue();
>   public $top;
> }
> // or
> abstract class Queue {
>   abstract public function enqueue($value);
>   abstract public function dequeue();
>   abstract public $top;
> }
>
> Of course in the second example the "abstract" is kind of useless, but it's
> for illustration. I've seen some cases (for example the example above),
> where it would be useful to define properties in interfaces, but instead I
> was forced to (in my eyes) misuse [1] methods. Right now I cannot safely
> write somethig like
>
> /**
>  * Must have a $top property
>  */
> interface Queue {
>   public function enqueue($value);
>   public function dequeue();
> }
>
> function foo(Queue $q) {
>   doSomethingWithTop($q->top);
> }
>
> Because I can never ensure, that $top exists. I always have to work with
> isset() here (or of course I use a getter, as mentioned earlier), what
> takes a little bit from the "usefulness" of interfaces ^^ The interface
> feels incomplete.
>
> Would like to hear some opinions, or maybe a summary of earlier discussions
> about this topic :)
>
> Regards,
> Sebastian

Reply via email to