Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82633 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 68526 invoked from network); 13 Feb 2015 18:00:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Feb 2015 18:00:33 -0000 Authentication-Results: pb1.pair.com smtp.mail=kontakt@beberlei.de; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=kontakt@beberlei.de; sender-id=unknown Received-SPF: error (pb1.pair.com: domain beberlei.de from 74.125.82.48 cause and error) X-PHP-List-Original-Sender: kontakt@beberlei.de X-Host-Fingerprint: 74.125.82.48 mail-wg0-f48.google.com Received: from [74.125.82.48] ([74.125.82.48:47219] helo=mail-wg0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 00/D5-40724-FBB3ED45 for ; Fri, 13 Feb 2015 13:00:31 -0500 Received: by mail-wg0-f48.google.com with SMTP id l18so15122254wgh.7 for ; Fri, 13 Feb 2015 10:00:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=oRuQXTdZnsCfsTUP/0yrKecu0P0H8SiQ4leALk/9hls=; b=bvWl7V7scyV9Vv7O5NKlT83u9HA2Ptg0uj8UcXR5kw8802kp9rzLLWCHFUTs4uF1+6 O0g1A64kVnL2JZH7rJsRd5r8sNL9LxBFli4RuVhR4agxqARNTVR6kl5LFCsALoS21+Pw M3MHPOTb0457SNB8wZnD5F5vEeOKndCMTqBA2XrKDGYy8pRPaFKi6QS3BQhWxDILjyCh jPlrGS6ZLpmkVs9c+VbAhoEW/PPdtB309DBx53HHZuZdbpyFCTEAGOmSopcCMSgXqmwd RySJZ7zVodjraWPqdYxC2PPyMm+frZknen2CYbhaoblMnl6m6pjMcm9FvLjS41b4YGS4 t/dQ== X-Gm-Message-State: ALoCoQlGJBfzHo1HmR06ofyAcmSDtwuDUahd5ztvJi999NWnys4UVENEAfpeYoR34zVQGOilv0SM MIME-Version: 1.0 X-Received: by 10.194.179.194 with SMTP id di2mr13852863wjc.4.1423850428145; Fri, 13 Feb 2015 10:00:28 -0800 (PST) Received: by 10.194.192.202 with HTTP; Fri, 13 Feb 2015 10:00:27 -0800 (PST) X-Originating-IP: [93.129.146.161] In-Reply-To: References: <8703B53E-2C4A-4AC6-95C4-D4F19C6D5221@ajf.me> <54DAF884.7000508@lerdorf.com> <203e611c8e0b03568a868b8d931aec37@mail.gmail.com> Date: Fri, 13 Feb 2015 19:00:27 +0100 Message-ID: To: Andrea Faulds Cc: Zeev Suraski , Rasmus Lerdorf , PHP Internals Content-Type: multipart/alternative; boundary=089e01419d1cfbb9a3050efc02ed Subject: Re: [PHP-DEV] [VOTE] Scalar Type Hints From: kontakt@beberlei.de (Benjamin Eberlei) --089e01419d1cfbb9a3050efc02ed Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Fri, Feb 13, 2015 at 5:59 PM, Andrea Faulds wrote: > Hi, > > > On 13 Feb 2015, at 16:18, Benjamin Eberlei wrote: > > > > Wait i almost forgot, it *does* have an effect on me, especially around > callback handling: > > > > https://gist.github.com/schmittjoh/778e044deacc6f1fe516 > > > > Essentially callbacks are evaluated in the mode they are called in, not > in the one they are defined. > > This is correct, yes. This is only going to cause a problem, however, if: > > * You add type hints despite not knowing what types will be passed > * You add type hints for the wrong types > > In both cases, you have only yourself to blame for your code not working. > So, I really don=E2=80=99t think it=E2=80=99s an issue. If you don=E2=80= =99t know what types will > be passed, why did you add type hints? If you know what types will be > passed and added incorrect type hints, why did you expect that to always > work? > > There is of course a third case: the function=E2=80=99s documentation lie= s and > claims the function will call your callback with certain types, and > actually passes different types. However, this is not a problem with the > RFC, and is something that could happen anyway. At least with this RFC, y= ou > might discover the bug in the library more quickly due to getting an erro= r. > > Anyhow, we could catch such errors prior to call-time by extending the > callable typehint to take a parameter list, such that parameter type hint= s > can be checked (with the same rules as used by inheritance). This would > solve your problem. > Yes, you are right, but think about the same problem in a changing code base. What if I pass the closure into a file that is now weak, and then this file changes to strict. You argue that hints are only responsible for a single file, but that is not true. When changing a file to strict, I have to verify that no closures are passed in that previously relied on weak type hints. Since there is no interface for callbacks (dynamic invocation) this means reviewing all the calling code as well. The same applies to any form of inheritance, see this example: https://gist.github.com/beberlei/6045bce658026cbdb6ab The user typehints against a class in weak mode (Foo) and makes use of that. Now depending which implementation is used (weak or strict) their code suddenly fails. Again this example is constructed and probably a bug on parts of the person building inheritance3.php (class Baz), however you only see this when calling index.php > > Thanks. > > -- > Andrea Faulds > http://ajf.me/ > > > > > --089e01419d1cfbb9a3050efc02ed--