Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94318 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 7070 invoked from network); 28 Jun 2016 23:52:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Jun 2016 23:52:46 -0000 Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 66.111.4.27 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 66.111.4.27 out3-smtp.messagingengine.com Received: from [66.111.4.27] ([66.111.4.27:41575] helo=out3-smtp.messagingengine.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1D/32-25084-BCD03775 for ; Tue, 28 Jun 2016 19:52:44 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 77BE9204F8 for ; Tue, 28 Jun 2016 19:52:41 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute2.internal (MEProxy); Tue, 28 Jun 2016 19:52:41 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=v5GyvzBJ0YLLPSA UnOi9sq3BhI8=; b=qDRnr0jje0O5Ltr/EgCHbMhEIDAV5DmMKm8Kzaf2sN7zfIS fzIC/+XylJBct67JAnqgelmtEwUKiF/roywtJtNTuyYTvShdUANWQHq58L4upT+f W4bh49O+pT0b8ZtpDSevymMKghxVDy8xVUEZLysjPNFGVKLsHaGpIYkHRrSo= X-Sasl-enc: LzmsrrvMvY3W1mdYC4pxqILqsl5R6/L6oEcK7Mt5dQCF 1467157961 Received: from [192.168.42.5] (c-50-178-40-84.hsd1.il.comcast.net [50.178.40.84]) by mail.messagingengine.com (Postfix) with ESMTPA id 242EFF29F3 for ; Tue, 28 Jun 2016 19:52:41 -0400 (EDT) To: internals@lists.php.net References: <211db59e-9c22-6df4-1f72-66ebbc5095bd@fleshgrinder.com> Message-ID: <57730DC8.5090607@garfieldtech.com> Date: Tue, 28 Jun 2016 18:52:40 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Simple Annotations From: larry@garfieldtech.com (Larry Garfield) On 06/28/2016 04:24 PM, Rasmus Schultz wrote: > 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... A possibly uglier but useful case would be where you have a large number of properties in an annotation and want to pass them in by name, but not using an anonymous array. (See also, my earlier Drupal examples.) To wit: <> class Node { public static function definition() { $def = new NodeDefinition(); $def->name = "node"; $def->label = "A Node"; $def->addLink('foo', 'bar'); // ... return $def; } // The rest of the node class here. } $annotations = $class_reflection->getAnnotations(); print get_class($annotations[0]); // prints "NodeDefinition". Or would that fail because it's not returning a self instance, but of another class? Rasmus, let me know when you have a proposal together and I'll try to dig up time to try rendering Drupal annotations in it again. :-) --Larry Garfield