Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:50268 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 39066 invoked from network); 16 Nov 2010 20:55:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Nov 2010 20:55:56 -0000 Authentication-Results: pb1.pair.com smtp.mail=tyra3l@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=tyra3l@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.161.170 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: tyra3l@gmail.com X-Host-Fingerprint: 209.85.161.170 mail-gx0-f170.google.com Received: from [209.85.161.170] ([209.85.161.170:39484] helo=mail-gx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 40/28-25421-ADFE2EC4 for ; Tue, 16 Nov 2010 15:55:55 -0500 Received: by gxk21 with SMTP id 21so749658gxk.29 for ; Tue, 16 Nov 2010 12:55:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:sender:received :in-reply-to:references:date:x-google-sender-auth:message-id:subject :from:to:cc:content-type; bh=tqvKTSAQbcG7hWBOk/uJBIJTwXx7bD9GF4cHBGP7ex0=; b=cbbErRCPpBuXEhajeSodPNfOY9Aw5lmLVtpbFJD20r0frAA7bLcgSSJnn79J6/1LyU vmqxs3nJK3Ei9fmEM94/QPv6xfHGSO/KrI3BYL4CGCZpFtEX2sY8g7OE3ABuNKu3mf6y Xj8yh0sYgr3e8yVpaGQ8rycZAWpePBdH8usv4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; b=AnNrhCR47LVwwavcCfK0gPQrss6ycQWFW2SQzrZBOxfMnvJOK2VQ8On4se8vHvXRzV IWlphOuNYP9NSdR5ayY59HnEJCyM/8oVVUG4SCw2qryNCQbxdf3+3PeeUcDl+pIQd+AT YrCUt/FDN1pStSCs3BUqT/DXuNmxpNzoNuI84= MIME-Version: 1.0 Received: by 10.90.60.16 with SMTP id i16mr10289219aga.114.1289940952306; Tue, 16 Nov 2010 12:55:52 -0800 (PST) Sender: tyra3l@gmail.com Received: by 10.90.53.4 with HTTP; Tue, 16 Nov 2010 12:55:52 -0800 (PST) In-Reply-To: References: Date: Tue, 16 Nov 2010 21:55:52 +0100 X-Google-Sender-Auth: 27OSKslGj4z5TJIbjdt704HsfW4 Message-ID: To: Simas Toleikis Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=0016363103253e532b049531c818 Subject: Re: [PHP-DEV] Traits and static methods From: info@tyrael.hu (Ferenc Kovacs) --0016363103253e532b049531c818 Content-Type: text/plain; charset=UTF-8 On Tue, Nov 16, 2010 at 6:46 PM, Simas Toleikis wrote: > Hello, > > I was just skimming through Traits RFC document on the wiki trying to find > a > practical use for them. The first thing that comes to my mind is a > Singleton > implementation - this is where I found myself literally "copying" most of > the code in the past. As far as I know there is no way to implement this > pattern properly in PHP without duplicate code (due to lack of multiple > inheritance/templating). > > Unfortunately, the same RFC document mentions this for trait methods: > > The static modifier is not supported, because it would change the methods > > semantics and references to $this would break. > > > > .. and that pretty much defeats Singleton-Trait implementation. Is there > any > particular technical/design reasons why traits can't handle $this inside > static methods just like regular static methods do (with a fatal error)? > > p.s. a Singleton-Trait implementation could look like: > > trait Singleton { > public static function getInstance() { ... } > } > > class Child extends Parent { > use Singleton; > } > > Child::getInstance(); > for reusable singleton pattern with php 5.3 http://www.slideshare.net/fabpot/design-patternrevisitedphp53 slide 11 and 12 Tyrael --0016363103253e532b049531c818--