Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80582 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 59816 invoked from network); 15 Jan 2015 19:20:32 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Jan 2015 19:20:32 -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.214.170 as permitted sender) X-PHP-List-Original-Sender: narf@devilix.net X-Host-Fingerprint: 209.85.214.170 mail-ob0-f170.google.com Received: from [209.85.214.170] ([209.85.214.170:48567] helo=mail-ob0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E0/61-49888-FF218B45 for ; Thu, 15 Jan 2015 14:20:31 -0500 Received: by mail-ob0-f170.google.com with SMTP id wp18so15256211obc.1 for ; Thu, 15 Jan 2015 11:20:28 -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=EFEeeWLtXU4MBvWEWr192OWUOe8Jm/C97FzuC5aV85c=; b=nGLaw8YNv2Gp6s9X7Vlr/+5dgNNF+NFjag7va/N+NOQKN3iFiRik40BRyIcxUu0Suz 8CbNnneCVSzzVeG095/wFVWR2N0ePdoasJryheNzBBUYcNRurjTVcSO22JIx2/SVdUXN FHwFvYByOpaN5PSJ0aplKcpGbJ8MQ6aMX0EK8= 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=EFEeeWLtXU4MBvWEWr192OWUOe8Jm/C97FzuC5aV85c=; b=XKPHlA+iGv4n8Zxw1AFPMvaFGT+0r4TY8pYhE6JHg/ff6V2AiQpee7C97pinT+aqmC FeAXw99CmRkgEU4IYOfiw0wkhrjeqLA9b40/D2odujg9rXSRBHzkDOeimoWCaLZ+xEHj Z8aFfr2atSzT6tAD0FUY8AFFMFD+SNmUwiugUpvkDO7d+jy9zAe23uccfZQ7NvAkcW8w iv1yPkYB1VA1AeKPijEcf7+ESH5wQMGU9HF1vlMEoTzIwe014Z5zOqmbt4BUxFY8NIhA NAbI2n1NJUsR2IvfKNmyHDNLVUWfrPIqI3feMk3q5E3+iAuFg4JMoLquPrOvrwflwD0B AXGQ== X-Gm-Message-State: ALoCoQntkeRG4lyuS2d3Aohja04gA074BzPQMusuYXav2LXXs3SiyHGCJL1Vb/MYvEEhW5T8Pmtv MIME-Version: 1.0 X-Received: by 10.60.52.176 with SMTP id u16mr4193584oeo.16.1421349628053; Thu, 15 Jan 2015 11:20:28 -0800 (PST) Received: by 10.202.214.146 with HTTP; Thu, 15 Jan 2015 11:20:27 -0800 (PST) In-Reply-To: References: <8DCD1B72-C81D-499E-B455-E4A042CD76E6@ajf.me> <4E2073DE-0951-498C-97BB-DDAC094F11FA@ajf.me> <9a033dd1f223f854e760924d118ab812@mail.gmail.com> <2ae0164cb9b9bf1c974d7a3c60af0466@mail.gmail.com> <6105ea99002e634373c09685310e26a6@mail.gmail.com> Date: Thu, 15 Jan 2015 21:20:27 +0200 Message-ID: To: Andrea Faulds Cc: Mike Willbanks , Zeev Suraski , Richard Quadling , Leigh , 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) Hi, On Thu, Jan 15, 2015 at 7:13 PM, Andrea Faulds wrote: > >> Now from that perspective I cannot rely that I am in strict and would h= ave to handle the default weak even although I declared in my class that i = wanted strict mode which only affected the code inside of that file. That'= s ultimately what I am saying and why I am stating it would have to handle = both conditions. In reality, you'd always act as if you were in a weak mod= e supporting that case. > > I=E2=80=A6 really don=E2=80=99t understand, I=E2=80=99m sorry. Are you co= mplaining that if a caller uses the weak mode, they are not bound by strict= types? Why do you want to affect the code of the caller? Consider this badly designed API: declare(strict_typehints=3DTRUE); const MODE_APPEND =3D 0; const MODE_TRUNCATE =3D 1; const MODE_PREPEND =3D 2; function write_file(string $path, int $mode, string $data) { // it's quite obvious } Somewhere else, you forget the parameters order ... declare(strict_typehints=3DFALSE); $path =3D '/important/file.dat'; $data =3D '1 year'; $mode =3D MODE_APPEND; write_file($path, $data, $mode); It's a bad example - an awful (and indeed, very much useless) API, combined with an absent-minded consumer. Yet, it demonstrates how putting the caller in control *can* cause a disaster. Of course, it is fair to say that this would be a very rare case, where it is the author's fault for both being bad at design and relying on a type-hinting feature that they don't understand, but it is also fair to say that it is possible that a lot of people assume that "strict_typehint=3DTRUE" affects definitions instead of calls (I know I would, if I wasn't following this list). But anyway, the point is - if you can't rely on it, why use it at all? I guess if your goal was to use strict typing as a debugging tool here, it makes *some* sense, but otherwise the way it works is completely inverted. ---- What I would suggest is the '(type) $weak' vs 'type $strict' syntax that was already mentioned. I've said this before, during the previous RFCs discussions - all of these proposals will fail, because they all suggest using the 'type $whatever' syntax and that automatically upsets the "other camp", whichever it is, but especially if the "other camp" is supporters of strict typing. That's the moment when they become opposition, while they could've otherwise not care because it's simply not their "battle". If both are proposed to co-exist in a clean way (instead of via a switch), I believe that we'll get substantially more positive opinions from both sides. And to hell with the "consistency" argument. Since when did PHP become *that* concerned about purity and high consistency levels? Call this a speculation, but barely a few people care for the the internal functions' behavior - most of us will be happy if they stay as is regardless of the kind of type-hinting that gets adopted. What we want is the features (plural!), not the philosophy. Cheers, Andrey.