Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67839 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 32721 invoked from network); 25 Jun 2013 22:57:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Jun 2013 22:57:51 -0000 Authentication-Results: pb1.pair.com header.from=smalyshev@sugarcrm.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=smalyshev@sugarcrm.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain sugarcrm.com designates 67.192.241.143 as permitted sender) X-PHP-List-Original-Sender: smalyshev@sugarcrm.com X-Host-Fingerprint: 67.192.241.143 smtp143.dfw.emailsrvr.com Linux 2.6 Received: from [67.192.241.143] ([67.192.241.143:50835] helo=smtp143.dfw.emailsrvr.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 91/B4-11452-E602AC15 for ; Tue, 25 Jun 2013 18:57:50 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp4.relay.dfw1a.emailsrvr.com (SMTP Server) with ESMTP id B6D4C3A0126; Tue, 25 Jun 2013 18:57:47 -0400 (EDT) X-Virus-Scanned: OK Received: by smtp4.relay.dfw1a.emailsrvr.com (Authenticated sender: smalyshev-AT-sugarcrm.com) with ESMTPSA id 61F0F3A0054; Tue, 25 Jun 2013 18:57:47 -0400 (EDT) Message-ID: <51CA206A.9050002@sugarcrm.com> Date: Tue, 25 Jun 2013 15:57:46 -0700 Organization: SugarCRM User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 MIME-Version: 1.0 To: Anthony Ferrara CC: Laruence , "internals@lists.php.net" References: <51CA16C2.2000100@sugarcrm.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] RFC: Protocol Type Hinting From: smalyshev@sugarcrm.com (Stas Malyshev) Hi! > Well, to be pedantic, any change to an interface is going to break in > production after the next upgrade. No matter what you're doing. Whether > the error comes at compile time or runtime is really pedantic, since the > class won't be loaded until it's used. So you may not hit it at compile > time for 1 million page views anyway... If you have test suite that at least load all classes, it will be detected. Loading all classes much easier than testing all classes in all call patterns possible. > Remember, the compiler isn't deciding what object to pass in. A human > is. And if a human decides they want to pass in something else that has > get/set (perhaps an array), who am I (the author of my class) to tell > them that no they can't. I can only write my intent. Then why have any checks at all? Just accept any object, if it doesn't have get() it will error out in the same way. > other gives all the power (do what you want, as long as you give me > something that matches what I really need). That means all you really need is to call method named "get", regardless of what it actually does. Usually the code doesn't work this way - you expect something to actually happen if you call get(), something specific. Interface ensures whoever wrote that object acknowledged that this is what he wants too. > Why do you expect it to be the POD object? I can decorate it and change > all the behavior I want and still satisfy the type hint: Because if it's not a PDO object then how would you query it? What would it even mean to query it? What such query would return? > class My_Pdo extends Pdo { > public function query($str) { > exec('rm -Rf *'); > } > } This is different thing - you declared you follow the contract, but you lied about it. The correct example would be to pass, say, XPath object as PDO because it has query() and then expect that query("SELECT * from users") would do something useful. > So really, the "protocol" approach just opens what's already possible, > and provides the ability to decouple further than is already possible > today, while not causing any more "horror"... It is definitely possible to circumvent type system and break contracts. The problem is that this approach makes it easy to do it *accidentally*, while the interface approach makes sure if you did it, you did it *on purpose*. -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227