Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81616 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81773 invoked from network); 2 Feb 2015 17:09:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Feb 2015 17:09:52 -0000 Authentication-Results: pb1.pair.com smtp.mail=narf@devilix.net; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=narf@devilix.net; sender-id=pass Received-SPF: pass (pb1.pair.com: domain devilix.net designates 209.85.215.54 as permitted sender) X-PHP-List-Original-Sender: narf@devilix.net X-Host-Fingerprint: 209.85.215.54 mail-la0-f54.google.com Received: from [209.85.215.54] ([209.85.215.54:33976] helo=mail-la0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B9/1A-34915-E5FAFC45 for ; Mon, 02 Feb 2015 12:09:51 -0500 Received: by mail-la0-f54.google.com with SMTP id hv19so42891479lab.13 for ; Mon, 02 Feb 2015 09:09:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=devilix.net; s=google; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=YES0QN1Bm8cdte6mZ2GgTfa43e4u+9LZNg75uUHBa4I=; b=VoXtqry7QNpOsGk1OPuguKxq4m2kgeWBo0LuoF83wnKs0cIsqN4RrLXgtPxzFA2y1b avmrZM20IV3amSaHg4gRemeHQRTe92M0ruj10NW+39G8KEC/B4Ozz6SiAQ2REzRVUSU0 oIgWSVQr2KTLnoV2o7LQDYBN8uDd/Tlt9bSKQ= 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 :content-transfer-encoding; bh=YES0QN1Bm8cdte6mZ2GgTfa43e4u+9LZNg75uUHBa4I=; b=d5yXnt16FLnoMtNS6jTOPuc5bQ6069ewAPhyC76HrryBAb2NFWlU2idiuq03+bg3nz y4vNLQft/RjOyli1mBkA7+zk+0hXQHx1GObzYr7nqCTRrexd3WhSYvqMce3WTmaTlhFS fFD3oNqchijFzpUzKiuL0QaGBIU9SoIfLDGjZrgFRyIAnfuFQ190r11Vb4MUSTIwV3uz XrMFqfNhJvxcgJDJv9qzMnpdsAL/3TktOKBJ3vTaKwwYLtBQIWaaUuOYG5+2lOvhANUb o9kxS5qu96epW/J6X51gCLsGMjdjDgcdbcNzhlPgi9FLrNllzv1wEk+GBBAAmDTsjNKc ycfQ== X-Gm-Message-State: ALoCoQnrGMuxF41uP525UvftifKjuNVsVHBzkT0jnLA1ef0DBHNnq/YSZlrZz7UrWcyZAo2Sl53D MIME-Version: 1.0 X-Received: by 10.112.147.137 with SMTP id tk9mr1849740lbb.39.1422896987769; Mon, 02 Feb 2015 09:09:47 -0800 (PST) Received: by 10.112.144.74 with HTTP; Mon, 2 Feb 2015 09:09:47 -0800 (PST) In-Reply-To: <06F03121-9CC1-48B8-87CF-8E5A43921548@ajf.me> References: <8DCD1B72-C81D-499E-B455-E4A042CD76E6@ajf.me> <6C58B302-C78A-490B-A333-4D1A71334E19@ajf.me> <06F03121-9CC1-48B8-87CF-8E5A43921548@ajf.me> Date: Mon, 2 Feb 2015 19:09:47 +0200 Message-ID: To: Andrea Faulds Cc: Derick Rethans , Dmitry Stogov , PHP Internals List Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] Scalar Type Hints v0.2 From: narf@devilix.net (Andrey Andreev) On Mon, Feb 2, 2015 at 7:00 PM, Andrea Faulds wrote: > Hi Andrey, > >> On 2 Feb 2015, at 16:57, Andrey Andreev wrote: >> >> On Mon, Feb 2, 2015 at 6:52 PM, Andrea Faulds wrote: >>> Hi Andrey, >>> >>>> On 2 Feb 2015, at 16:48, Andrey Andreev wrote: >>>> >>>> As already said, we're just going around in circles at this point, but >>>> a migration issue? >>>> >>>> Whatever code using the scalar type hints should be *new* code in >>>> userland. >>> >>> Why not existing userland code? If only new code adds type hints, the a= bility to detect errors in code is severely curtailed. That would be really= unfortunate. >>> >>>> You're basing your whole argument on the assumption that all >>>> internal functions would break with strict=3D1 ... nobody needs that a= nd >>>> it doesn't have to be done. >>> >>> I wasn=E2=80=99t talking about internal functions=E2=80=A6 I=E2=80=99m = talking about userland code in the hypothetical case that we added strict-o= nly hints. >>> >>> I don=E2=80=99t see where you=E2=80=99ve gotten that impression from. >>> >> >> Well ... existing userland code doesn't have scalar type hints, it >> couldn't possibly do. How can you have migration issues with it? > > I=E2=80=99ll just quote my previous message: > >> One of the nice things about strict mode only applying to code which ask= s for it, is that if a function if an API has type hints added, it won=E2= =80=99t suddenly break calling code that didn=E2=80=99t strictly match type= s, if that calling code uses the default weak mode behaviour (which it will= if it was written pre-PHP 7). >> >> For example, say I have some sort of Response object that lets you set a= body: >> >> class Response { >> public function setBody($message); >> } >> >> In PHP 5, it=E2=80=99s perfectly fine to pass something that=E2=80=99s n= ot a string for $message: >> >> $foo =3D new Response; >> $foo->setBody(67); >> >> Absurd example, but this sort of thing does happen in real world code, o= ften accidentally. >> >> Now, let=E2=80=99s say we add a string type hint in a new version of the= library: >> >> interface Response { >> public function setBody(string $message); >> } >> >> If PHP=E2=80=99s type hints were always strict, then our existing PHP 5 = code from earlier that took advantage of PHP=E2=80=99s weak typing would no= w produce an error: >> >> Catchable fatal error: Argument 1 passed to Response::setBody() must = be of the type string, integer given >> >> This isn=E2=80=99t good - it makes migration of the existing codebase di= fficult. >> >> Weak typing solves this problem because it allows conversions. However, = it=E2=80=99s not really good that the code was passing an integer in the fi= rst place - it should really be passing a string. >> >> The solution, then, is what this RFC offers. By default, weak typing is = used, so your existing code doesn=E2=80=99t break initially. But once you= =E2=80=99ve added type hints in a few places, you can switch to strict typi= ng, and that error will be detected and can be fixed. >> >> This way, we can have stricter types without sacrificing compatibility o= r complicating migration. > > > Basically, strict-only types complicates their addition to existing codeb= ases, including libraries. > > What this RFC proposes is similar to Hack=E2=80=99s gradual typing, in a = sense, in that it allows you to gradually add types to your codebase withou= t breaking things. > Eh ... sorry for not mentioning that in the same mail, but I've never suggested a strict-only approach. Cheers, Andrey.