Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67840 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 34100 invoked from network); 25 Jun 2013 22:59:32 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Jun 2013 22:59:32 -0000 Authentication-Results: pb1.pair.com smtp.mail=ircmaxell@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ircmaxell@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.49 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 209.85.212.49 mail-vb0-f49.google.com Received: from [209.85.212.49] ([209.85.212.49:54743] helo=mail-vb0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 54/05-11452-3D02AC15 for ; Tue, 25 Jun 2013 18:59:32 -0400 Received: by mail-vb0-f49.google.com with SMTP id 12so9901624vbf.8 for ; Tue, 25 Jun 2013 15:59:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=ZlBB0gJinxQU0p5lCJ437tw1lx+/4hNR+9yZUg7xN88=; b=HXFODfDuzp5o2Z95TSliV8wprf0DDK2WuAwHLt1dAogw8IVFGf5r6NTgOTYwZKcus3 q6nhCIFQ3cbcNOIturnbYK6xU9g9hJnvdGr+GLBSm2juR8Ky7SjEZnFiYz1sFDDZ8PRu 2J0+3hZjehaMgjZze4LVMtD40ZKPdCCCBoj7+cpHJL8n99vV57VmovlXXvKNanQXOjDF hWSw7BT5B/0x6xGgieXOY8UPVuwbFreP4Hf7U9Wc+hdF8NrBqtv7tpcSmHXnpauwsU6i c+njOaXCmgx0xSIbUDGsGwzEmjXXlJzIQ0cOnesuNigbLXJIQBm2raWlIjGGNRLFpmQh Uh0A== MIME-Version: 1.0 X-Received: by 10.221.36.4 with SMTP id sy4mr756793vcb.11.1372201169557; Tue, 25 Jun 2013 15:59:29 -0700 (PDT) Received: by 10.58.94.201 with HTTP; Tue, 25 Jun 2013 15:59:29 -0700 (PDT) In-Reply-To: <51CA1C93.6080500@sugarcrm.com> References: <51C9FA9C.8050403@sugarcrm.com> <51CA1C93.6080500@sugarcrm.com> Date: Tue, 25 Jun 2013 18:59:29 -0400 Message-ID: To: Stas Malyshev Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a11339f3845a18404e0027bc3 Subject: Re: [PHP-DEV] RFC: Protocol Type Hinting From: ircmaxell@gmail.com (Anthony Ferrara) --001a11339f3845a18404e0027bc3 Content-Type: text/plain; charset=ISO-8859-1 Stas, I don't see how you can see it's not - it does method matching on every > call. It just doesn't make sense that doing something N times is faster > than doing something 1 time. That may be true only if you load classes > you don't ever need (no autoloader? why?) - but even in this case your > model still has to load the class once the typing statement is > encountered (actually, once it is compiled if inheritance is in place > since you have to check it against inherited interface to see if the > inheriting interface did not change it in incompatible way). I'm not making things up. Look at the patch. Run it. It does not slow things down. It only does method matching on the first call. Every subsequent call caches it. And let's try running the same benchmark with 1 iteration (taking caching out of the picture): Interface in 1.5974044799805E-5 seconds, 1.5974044799805E-5 seconds per run Protocol in 1.4066696166992E-5 seconds, 1.4066696166992E-5 seconds per run Native in 6.9141387939453E-6 seconds, 6.9141387939453E-6 seconds per run It's **still** faster. Want to dig through the code to see why? Go for it: https://github.com/ircmaxell/php-src/compare/protocol_proof_of_concept But I'm not making this up... > > As far as "you can easily add implements", that ignores the relationship > > where you may not own all of your code. I know I've been in many > > situations where I've "just needed to add an interface" to a class, > > except that I didn't own that class. Which led me to either drop the > > type-hint entirely, or do some nasty work-around. > > If you don't control the code, how can you ensure it actually does what > your contract requires it to do - and keeps doing it in the next > version? If you can't ensure it - what these checks are worth? What > exactly will you be checking and what value would you derive from these > checks that would not be present otherwise? So nobody should ever use libraries, because they can't be sure of that code... So... > > Why not? > > > > Seriously, why not? > > Because check that says "accept any object that has __call" doesn't seem > very useful for me. What exactly is it checking? It's checking that fatal method-not-defined erros won't be thrown... And avoiding E_FATAL is quite significant... > > This gets down to a deeper philosophy. Control when you need it, but > > freedom where you don't. Not everyone is going to want to program like > > this. But the point is that a lot of people do today, and why not offer > > some engine level help to them...? > > We already have support in the engine for them. Typing in PHP is not > mandatory, never was and I sincerely hope never will be. So you can pass > any object anywhere. What exactly checking for __call adds there? It gives the ability for a method to be defensive by preventing E_FATAL errors. That's not adding something significant? (as to the rest, I don't want to keep arguing the same rabbit hole over and over. I've made my points, take them or leave them). I agree the use-cases are slightly weak. This is a draft RFC. It's supposed to help identify the areas where we can improve it. Help identify use-cases. Help dig it out. But right now, this discussion is completely counter-productive. Anthony --001a11339f3845a18404e0027bc3--