Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:97481 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 11629 invoked from network); 29 Dec 2016 13:18:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Dec 2016 13:18:34 -0000 Authentication-Results: pb1.pair.com header.from=ocramius@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ocramius@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.210.172 as permitted sender) X-PHP-List-Original-Sender: ocramius@gmail.com X-Host-Fingerprint: 209.85.210.172 mail-wj0-f172.google.com Received: from [209.85.210.172] ([209.85.210.172:33292] helo=mail-wj0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F7/53-04761-52D05685 for ; Thu, 29 Dec 2016 08:18:31 -0500 Received: by mail-wj0-f172.google.com with SMTP id tq7so120997071wjb.0 for ; Thu, 29 Dec 2016 05:18:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=il5v3E3okPpBI6hN/G4ddRfXxvPIAv3VrFJkDBOU2rI=; b=MwYfW9uaXGGyP5Y7hiGQcS6US0qGK7jIfqA4aAP6SVUQ2K6f13Z35RjsYFiSvSdP8v Ec2cYXet6NLuOnTgtBCmdJQhYuZM4c3+vfeLHRkJVHLP9QjU8MPaciDSR70q39a5DB5+ pM8YE6nfSOrFdNFWP7AkYfd7PxJKTCC08wiXiwu5OAAEYEuEMv8Aiblj3uicyF98LEtc X0lKzDIWCCV1+m3t1JiSutwmCUAfD7pIc3MY1OSFVh0hIcp/nmwcHM/x541SpIlcKEqo yDzcSr5VXtb/dmim7A4kzqFrJOg8VIKf63fQTSOYIOXcbmg4MmVR8dl6lfTEdA/eQVGq kZbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=il5v3E3okPpBI6hN/G4ddRfXxvPIAv3VrFJkDBOU2rI=; b=qWIGSxJ7UFJ5ptqv5R3I5YD926M27kSkS0fbk3vWsN1IsldM7xyr4ED18arqJDJf+s hFy/KsxILc28fdKJxWFsNV9zz0GbOHOf8xGeca+1Fx2BHKRHmJkjDvj/5DSwhB2/fupp n//FX7UpsbdBVmNFoFV0uvCeWDsl0SHlXugkixBsQQf95TbMjvK7gqhfxJVSJHy0F7id 7DtZjo9jO8vW1/jpfTQnfREWbVS8nM1LaP4bAECYwxapKRgosCVBFDf0y5y3N5DleVlx wKACih2mqNCGUbZNu5igTvJEDHy9mNUeC62VOyyG5UkYY8kI8syZ2y0MpUy+Zpydt6jD i3pA== X-Gm-Message-State: AIkVDXLiS0DYKDQ06g+KsjKuUiF+vrZEWo7PBsw5dtOv38paQHgFMsQ26PwVWD+sfG7XXpti9deL6ejLbsZTqQ== X-Received: by 10.194.157.165 with SMTP id wn5mr35090843wjb.8.1483017506087; Thu, 29 Dec 2016 05:18:26 -0800 (PST) MIME-Version: 1.0 Received: by 10.194.173.106 with HTTP; Thu, 29 Dec 2016 05:18:05 -0800 (PST) In-Reply-To: <2aecc3f2-5e9d-907f-029b-5c60eb134b33@rochette.cc> References: <2aecc3f2-5e9d-907f-029b-5c60eb134b33@rochette.cc> Date: Thu, 29 Dec 2016 14:18:05 +0100 Message-ID: To: Mathieu Rochette Cc: PHP internals Content-Type: multipart/alternative; boundary=089e013c656aa5683b0544cbeb1e Subject: Re: [PHP-DEV] Decorator classes From: ocramius@gmail.com (Marco Pivetta) --089e013c656aa5683b0544cbeb1e Content-Type: text/plain; charset=UTF-8 On Thu, Dec 29, 2016 at 2:12 PM, Mathieu Rochette wrote: > Hello internals, > > I find that using the decorator pattern is very verbose and maybe > something could be done about that, > an article[1] I saw proposed a "decorates" keyword to solves this, here is > how it might look like in PHP: > > interface Foo { > public bar(); > public taz(); > } > > class EchoFooBar decorates Foo { > public function bar() { > $this->logger->debug("foo bar"); > return $this->decorated->bar(); > } > } > > class LoggedFooTaz decorates Foo { > private $logger; > > public function __construct(Foo $decorated, Logger $logger) { > $this->logger = $logger; > $this->decorated = $decorated; > } > > public function taz() { > $this->logger->debug("foo taz"); > return $this->decorated->taz(); > } > } > > * the constructor is optional and default to take the first argument and > put it in $decorated > * if the constructor is provided PHP check that $decorated is set and > implements the decorated interface or class > * all public methods not overridden are automatically proxied to the > decorated object > > There is at least a few different ways to go about this, the previous > example was just to give you a preview of what it could be. If there is > interest I'd like to write an RFC for this :) > > What do you think about this ? > > > thank you > > > [1] https://dzone.com/articles/is-inheritance-dead > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > Just my 2 cents: Too much magic syntactic sugar, whereas you are just saving very little time while implementing a few method stubs that take.. Yet, in order to achieve that, you added a huge amount of complexity for all the tooling that relies on the AST, including PHP itself. . Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ --089e013c656aa5683b0544cbeb1e--