Re: internals Digest 2 Dec 2012 00:53:48 -0000 Issue 2845

From: Date: Sun, 02 Dec 2012 01:16:58 +0000
Subject: Re: internals Digest 2 Dec 2012 00:53:48 -0000 Issue 2845
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-64133@lists.php.net to get a copy of this message
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-help@lists.php.net> wrote: > From: Sebastian Krebs <krebs.seb@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

« previous php.internals (#64133) next »