Re: Attributes/Annotations Case Study: Drupal

From: Date: Mon, 02 May 2016 06:12:16 +0000
Subject: Re: Attributes/Annotations Case Study: Drupal
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-93028@lists.php.net to get a copy of this message
Hey Stas, On 1 May 2016 at 00:14, Stanislav Malyshev <smalyshev@gmail.com> wrote: > > $def instanceof MyAnnotation; //TRUE > > That looks fine, however the problem is that if MyAnnotation is a class, > then PHP does not have multiple inheritance, so it's the only class it > can be. And given that your class has no methods, $def has no methods > either and can not have any semantics besides simple data object. Which > begs the questions: Note that an annotation usage here is basically a constructor call for a concrete instance. Still, this doesn't deny implementing interfaces for annotations, then implementing those on the concrete annotation class. I don't see the need for multiple inheritance therefore. a) why it needs to be a class/object at all Usually as a replacement for what you'd have as a "struct" in C. Having a class definition provides some basic security on what is going on (type-hints, etc). You probably wouldn't ever have behavior on an annotation though, since it is just a data structure: in fact, most of the existing annotations in PHP userland libs are currently just classes with constructor+public properties. Cheers, Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/

« previous php.internals (#93028) next »