Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:50258 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 94958 invoked from network); 16 Nov 2010 17:46:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Nov 2010 17:46:36 -0000 Authentication-Results: pb1.pair.com header.from=simast@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=simast@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.210.42 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: simast@gmail.com X-Host-Fingerprint: 209.85.210.42 mail-pz0-f42.google.com Received: from [209.85.210.42] ([209.85.210.42:40341] helo=mail-pz0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CA/50-25421-B63C2EC4 for ; Tue, 16 Nov 2010 12:46:28 -0500 Received: by pzk30 with SMTP id 30so17051pzk.29 for ; Tue, 16 Nov 2010 09:46:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:date:message-id :subject:from:to:content-type; bh=rI1DNj/A83Nt9kX/FkEEO05ZsOWbhp1IFFKiBKECfSg=; b=xT7cxoHSUm7OGI6h3svNJtyKGpK//zCnuX3o16U/6a+cty7SbbOp0zxytieF9YLcfv HCy2i0r90ib+Ow+fOSQnje7PZihvPI1h59gxQ8rSV9XleVE/V8TVxFhz2SoDKPoBjU5F HhrtcDnxBqHLOhA0DJGCwB+ga8yQAbhHld7q8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=xpmw8xJFgBigV5UxqN1+xr8vJNaRLgnHhRbuvogvsOEtE5fD0ujfzkqv1zdJkD+r1X tDR3ZHljF4evSRE0mllAsbNv3c1gYFZDwhKNwt+w6HNryMULB+bSkJRADVfq5yssaAId 4A/wopD/Y4iUiyTVE0s0vTnG6WTC8hVtyEY7k= MIME-Version: 1.0 Received: by 10.229.101.197 with SMTP id d5mr6424240qco.220.1289929569779; Tue, 16 Nov 2010 09:46:09 -0800 (PST) Received: by 10.229.250.77 with HTTP; Tue, 16 Nov 2010 09:46:09 -0800 (PST) Date: Tue, 16 Nov 2010 19:46:09 +0200 Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary=001636aa2b8ccabfe304952f2173 Subject: Traits and static methods From: simast@gmail.com (Simas Toleikis) --001636aa2b8ccabfe304952f2173 Content-Type: text/plain; charset=UTF-8 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(); --001636aa2b8ccabfe304952f2173--