Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92649 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 52974 invoked from network); 22 Apr 2016 15:56:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Apr 2016 15:56:17 -0000 Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 66.111.4.26 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 66.111.4.26 out2-smtp.messagingengine.com Received: from [66.111.4.26] ([66.111.4.26:50120] helo=out2-smtp.messagingengine.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 10/49-14036-0A94A175 for ; Fri, 22 Apr 2016 11:56:16 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id E8DE825BC5 for ; Fri, 22 Apr 2016 11:56:13 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute4.internal (MEProxy); Fri, 22 Apr 2016 11:56:13 -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=o6p8Ab3yNuwWKHi jGZIYyNU0srM=; b=Nx7yCEkwrt+WAMX8VI3SPM6ZeNHwEsKcmTDqPe4aAJY/NI1 dp+fKxJfDjR5q8qgCA3NKvUlBOmSzgD4dwpnZOsdYWWRJBv7p85q2bt7GYPUYsnX nY5rOE6vbfNyX5gW1z9t3EuAIsK168QwQIeWleS+3fbYg8il93mVc5n154l4= X-Sasl-enc: h+GOYX+Lh48p6pCiozfu4V6COY1AaAzJZl6bdIIJPQwr 1461340573 Received: from Crells-MacBook-Pro.local (unknown [63.250.249.138]) by mail.messagingengine.com (Postfix) with ESMTPA id B0C58C0001F for ; Fri, 22 Apr 2016 11:56:13 -0400 (EDT) To: internals@lists.php.net References: <571965D1.9020102@zend.com> <5719CDB2.90103@zend.com> Message-ID: <571A499D.4090200@garfieldtech.com> Date: Fri, 22 Apr 2016 10:56:13 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.0.1 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] PHP Attributes From: larry@garfieldtech.com (Larry Garfield) On 4/22/16 10:39 AM, guilhermeblanco@gmail.com wrote: > On Fri, Apr 22, 2016 at 3:07 AM, Dmitry Stogov wrote: > > >> >> 3- Did you put any thought on inheritance? What I mentioned in comment #1 >> is even smaller than what you implemented in RFC. >> Assuming you keep the RFC approach, did you consider support overrides, >> inherit, etc? >> >> >> In my opinion, attributes don't have to be inherited. >> If you think differently - please explain your point. >> > Of source I can. > A simple case would be to increate visibility of the inherited property. It > was declared in a parent class as protected, but now you want public, and > you still want to keep all parent defined Attributes. > Another example is like we do in Doctrine. We support a callback system > which we named as lifetime callbacks. Pre-persist is one of them, which is > called every time a given Entity is about to be persisted into DB. When > you're dealing with inheritance, you can potentially override the method > content and you still want to trigger the same operation as if it was > untouched. Example: > > use Doctrine\ORM; > > trait Timestampable { > protected $created; > protected $updated; > > <> > public function prePersist() { > $this->created = $this->updated = new \DateTime("now"); > } > > <> > public function preUpdate() { > $this->updated = new \DateTime("now"); > } > } > > <> > class User { > use Timestampable; > > public function prePersist() { > // Add my custom logic > } > } > > The implication is that through a simplistic approach, inheriting (or > overriding) is not clear and I can't figure it out an easy way to achieve > that. > Now if we go towards calling a function or class constructor like I > mentioned before, then we could easily build structures like __Inherit, > __Override, etc. > Here's another example from a Doctrine-using project I built a while back. (Not the exact code, but the same concept; I've adapted it to PHP 7 types as well): interface Ownable { public function getOwner() : string; public function setOwner(string $u); public function isUnowned() : bool; } trait OwnableTrait { /** @ORM\String **/ private $owner = ''; public getOwner() : string { return $this->owner; } public setOwner(string $u) { $this->owner = $owner; } public function isUnowned() : bool { return $this->owner == ''; } } /** @ORM\Entity */ class Product implements Ownable { use OwnableTrait; // ... } class Widget extends Product { // ... } For annotations to work for this use case, reflecting on the properties of Widget would need to include $owner, and it would need to include the ORM\String annotation. (True regardless of whether annotations are array or object based.) -- --Larry Garfield