Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98468 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 86903 invoked from network); 10 Mar 2017 10:57:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Mar 2017 10:57:47 -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 74.125.82.179 as permitted sender) X-PHP-List-Original-Sender: narf@devilix.net X-Host-Fingerprint: 74.125.82.179 mail-ot0-f179.google.com Received: from [74.125.82.179] ([74.125.82.179:33487] helo=mail-ot0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F3/65-31244-AA682C85 for ; Fri, 10 Mar 2017 05:57:46 -0500 Received: by mail-ot0-f179.google.com with SMTP id 19so74548841oti.0 for ; Fri, 10 Mar 2017 02:57:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=devilix.net; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=+poIKfRJMTYPnazMbZ+w/slhosSwLrkMVNmctF4kyK8=; b=YXCozZMcpM9ALVzer5ZufM/ahrm/KkvSHCQCUGAR0iiIIRunRl7tmWWJPLz/fGycms 9IjAsGVYxXbTEcXWScIT+RFWrRyk1BA+z+L/TIngl672iMAGJhzwWdKEP8GoiNc2y8ZW SHTi31KgzpAQeYir/5ng4PkF9HH8LNzYDWdFA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=+poIKfRJMTYPnazMbZ+w/slhosSwLrkMVNmctF4kyK8=; b=mOpt/Igp4fG4XQWAS5DxUABNsalffvfZQgDXHibGCmgQe2m/K5TtWmXLy9nvs33HsO iu3kYByTpcjSYSlZnO3vRy8uFdE4KUEhwUMGuDHQslhKYSixiIBfqpFH9iD1cmnc4oFb 9XEa9wzbeOJw9qJUIfqM6213y/ajWf8AgpCH2/kywe6fk6JpbxrwR/yuQCRagADz1/sq HZeFpoHyrBXDahspVnzVPIpdRdi5kIf/h26EMvE+oKquINInurGlOiDUCrqMv78VOYod kaRdUoaRblIBKXILPEaC9jkrTH++GhfWNQkMEsW/A9ag11yucueS5uoVHcbyF5x+cSpc jqKg== X-Gm-Message-State: AFeK/H0+ach0ukGqhUCB8Vah+wNEysznGY85yZuHBTcwc9YH6n9RSkhBlcKyaQSKKb9Gqgm2BgXEzt76d+EYVA== X-Received: by 10.157.3.87 with SMTP id 81mr8847766otv.230.1489143463349; Fri, 10 Mar 2017 02:57:43 -0800 (PST) MIME-Version: 1.0 Received: by 10.182.242.83 with HTTP; Fri, 10 Mar 2017 02:57:42 -0800 (PST) In-Reply-To: References: <24efb0e7-b0e3-68ed-5f42-2d5481f8f291@gmail.com> <44add374-6c4b-399a-c542-8d7f100dfaa3@fleshgrinder.com> Date: Fri, 10 Mar 2017 12:57:42 +0200 Message-ID: To: "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [Discussion] is_string(), string type and objects implementing __toString() From: narf@devilix.net (Andrey Andreev) Hi, On Thu, Mar 9, 2017 at 7:47 PM, Fleshgrinder wrote: > On 3/9/2017 12:47 PM, Andrey Andreev wrote: >> How can "any other scalar value" work? Using the cookie and headers examples: >> >> - booleans can be used as On/Off flags for the secure and httpOnly >> cookie attributes, but aren't valid literal values for any of the >> attributes, or any HTTP header. >> - integers are valid as a few headers' values - that is true, but >> certainly in a minority of cases >> - floats may be used for the q(uality) attribute in content >> negotiation (and nothing else AFAIK), but that is a very, very narrow >> domain >> - null is obviously invalid ... who sends an empty header? And if you >> have a use case where you do want to use them, we can already make >> anything nullable >> >> Of course the string values should be validated, unless you want to >> allow setting arbitrary headers, e.g.: >> >> abstract function setHeader(stringable $name, stringable $value); >> >> ... but filtering out the known to be invalid types *is* validation. >> And just that much better if it happens at compile time. > > Because: > > - bool(true) = '0' > - bool(false) = '1' > - int(n) = 'n' > - float(n) = 'n' > - null = '' > - object(s) = 's' > - string(s) = 's' > > All values are possible values that I can pass to you if you use the > string type constraint. Hence, all these types are valid string values > if you request a stringable. > Yes, they're valid string values, but the examples I gave were meant to show that context can make them predictably invalid, and hence why strict typing is desirable. > Stringable should work exactly like the string constraint in non-strict > mode, but regardless of the strict mode. The difference to a scalar type > constraint is that the passed values are always converted to a scalar > string, hence, the source type is unknown to the receiver. > I'm not really interested in making "strict mode" less strict - it's already opt-in and non-enforceable. I want ways to write stonger-type code in "non-strict mode", because the fact that "strict mode" is non-enforceable means I can never rely on it. Cheers, Andrey.