Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67838 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 31298 invoked from network); 25 Jun 2013 22:54:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Jun 2013 22:54:37 -0000 Authentication-Results: pb1.pair.com header.from=florinpatan@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=florinpatan@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.219.46 as permitted sender) X-PHP-List-Original-Sender: florinpatan@gmail.com X-Host-Fingerprint: 209.85.219.46 mail-oa0-f46.google.com Received: from [209.85.219.46] ([209.85.219.46:45932] helo=mail-oa0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8E/54-11452-BAF1AC15 for ; Tue, 25 Jun 2013 18:54:36 -0400 Received: by mail-oa0-f46.google.com with SMTP id h1so14128011oag.5 for ; Tue, 25 Jun 2013 15:54:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=qFcIYsXp+dEoPL3jgEjEEG2cC0u4hRxMAdEDxuUekxw=; b=HQ3DInHXFk+kf9SU4rX19kjqyxbMXGWk5/V4LY1yOHJyeLRtW7P3YlV/3w9t/f2UR7 HH0au97V0paD/2UcevuBCJfycXfmp3MSxkMdoENYmFsMyF43c/vPU9y+60NaUUzZwurc VoDeCjgg0vnrJ/yDCru+oevb2XTbQgvaghpAK0EhcWQImREFD+YqibxxyZJWYdtR9u3+ dCxbgixxsnlKCOhRgm91oeALqYS3PF8sol8nR7DxhsH3oIRTvEAXNsPymCRfgP9tJPX2 eIB/7jW24UuDo/6SdFq9kmQSYBsaSYhjwmwRuWstnlgRXG6NyvgQ3agsknOvUmzZ77AF z+sQ== X-Received: by 10.60.68.66 with SMTP id u2mr498570oet.82.1372200873251; Tue, 25 Jun 2013 15:54:33 -0700 (PDT) MIME-Version: 1.0 Received: by 10.76.18.161 with HTTP; Tue, 25 Jun 2013 15:54:03 -0700 (PDT) In-Reply-To: References: Date: Wed, 26 Jun 2013 00:54:03 +0200 Message-ID: To: Anthony Ferrara Cc: Laruence , "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] RFC: Protocol Type Hinting From: florinpatan@gmail.com (Florin Patan) Hi, On Tue, Jun 25, 2013 at 11:54 PM, Anthony Ferrara wrote: > Laruence, > > Hey: >> Just one question, usage? why we need this? (run-time check is >> slow and I can not think out of a case then we must need it) >> > > 1. Library implementers don't need to declare a dependency for a third > party library to use the interface from it. > > This may sound trivial, but imagine this. Right now Zend and Symfony have > very similar providers for certain tasks. One of the ones that comes to > mind (besides logging) is caching. If you want to use a Zend component in > an Symfony app while still using caching today, you'd need to shim together > an adapter to satisfy the zend cache interface with the symfony cache > interface. Which means your project now depends on all three, as well as > requiring the zend cache code for the sole purpose of loading the interface > required by the component. > > That's loading a LOT of code that you don't need, just to avoid having to > setup two caches... > > Instead, the zend component could depend on the narrow api that it needs. > It only calls the ->get($key) and ->set($key, $value) methods, so create a > (new?) interface with that limited API, and then type against it as a > protocol. Now that interface still would need to be loaded, but the Symfony > class can resolve that interface directly. Without the need to load > anything from Zend cache (said caching interface doesn't need to be there) > or wire anything else for you. > To me this seems like a pseudo-problem. If Symfony and Zend would actually want to use components from each other then they shouldn't try to avoid hinting at the corresponding interface directly. I would feel much better to know that my project takes 200 more KB of data on the hard drive and the autoloader can automatically load the interface from Zend when I'm in a Symfony2 project and I'm hinting that interface. And here's a problem that I could see of it: what happens when this code? // Third party Mighty Logger Library interface Logger { public function log($argument); } // My beloved implementation class Demo { public function log($argument) {} } class UseMe { public function shazam( $logger) { $logger->log('shazam'); } } $demo = new Demo(); $useMe = new UseMe(); $useMe->shazam($demo); becomes // Third party Mighty Logger Library interface Logger { public function log($argument); public function unlog($argument); } // My beloved implementation class Demo { public function log($argument) {} } class UseMe { public function shazam( $logger) { $logger->log('shazam'); } // New method written by different enthusiastic programmer public function kazam( $logger) { $logger->unlog('kazam'); } } $demo = new Demo(); $useMe = new UseMe(); $useMe->shazam($demo); $useMe->kazam($demo); From code quality point of view, if I want to use methods from a certain class / interface, I could always hint at that. And if you look at my example, you clearly see that you should modify this as it's right there, but when using a IoC at the object comes from another place it might not be that easy to find out there Demo is and implement new stuff out. As for setting up a third library of common interfaces, maybe FIG could solve that, if they ever pass the point when they create laws about laws to govern them. If I got this wrong then maybe you should consider improving your examples because right now, from those examples alone it just looks like a more problematic way of having a object hinted at. Best regards ---- Florin Patan https://github.com/dlsniper http://www.linkedin.com/in/florinpatan