Re: [RFC] Simple Annotations
| From: | Rasmus Schultz | Date: | Tue, 28 Jun 2016 21:24:49 +0000 |
| Subject: | Re: [RFC] Simple Annotations | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-94317@lists.php.net to get a copy of this message | ||
This was just an example of a value object - for example:
class HttpMethod {
private $method;
protected function __construct($method) {
$this->method = $method;
}
public function getMethod() {
return $this->method;
}
public static function get() {
return new self("GET");
}
public static function post() {
return new self("POST");
}
// ...
}
You could picture using a flyweight constructor inside those factory
methods maybe, and probably other patterns... I think there's plenty
of cases for "named constructors", this is just the PHP variety of
that. There are also cases (such as this one) where only certain
constructions are permitted - allowing any string for HTTP method
(e.g. wrong names, wrong case etc.) is prevented by protecting the
constructor...
On Tue, Jun 28, 2016 at 9:10 PM, Pedro Cordeiro <pedronaroga@gmail.com> wrote:
>
>> << HttpMethod::post() >> // equivalent to static method-call
>> HttpMethod::post()
>
>
> What would this, specifically, do? Would it call HttpMethod::post() when the
> class gets instantiated and return its return on a
> ReflectionClass::getAnnotations()? Why is it necessary to be able to
> evaluate expressions on annotations? I do agree that throwing
> errors/exceptions when classes are not found is needed (otherwise we wont be
> able to use value-objects), but evaluating expressions seems a little crazy
> for me... why should metadata be computed in runtime?