Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98466 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 82844 invoked from network); 10 Mar 2017 10:18:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Mar 2017 10:18:54 -0000 Authentication-Results: pb1.pair.com smtp.mail=cmbecker69@gmx.de; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=cmbecker69@gmx.de; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmx.de designates 212.227.17.21 as permitted sender) X-PHP-List-Original-Sender: cmbecker69@gmx.de X-Host-Fingerprint: 212.227.17.21 mout.gmx.net Received: from [212.227.17.21] ([212.227.17.21:55423] helo=mout.gmx.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8B/A4-31244-C8D72C85 for ; Fri, 10 Mar 2017 05:18:53 -0500 Received: from [192.168.2.100] ([217.82.238.234]) by mail.gmx.com (mrgmx101 [212.227.17.168]) with ESMTPSA (Nemesis) id 0MQvDO-1cg7WR17QE-00UMML; Fri, 10 Mar 2017 11:18:49 +0100 To: Rowan Collins , "internals@lists.php.net" References: <24efb0e7-b0e3-68ed-5f42-2d5481f8f291@gmail.com> Message-ID: Date: Fri, 10 Mar 2017 11:19:03 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:tKHDrusSYkLRz4q238bMKVpqPHN6enE2Qql+TVt+sDtKNKSjtOR 7rwRj2tXIGinVH421Wodos/yhw3N8N4Z7iczwOb6WrtChHmy/hMhDOW9SaXB47cS0Ua2/y2 nW2bCoEqQfoGerq4IaUJjHjXWekrsPKPQQkgrN4mFxmJghTiQm6ghe1TnZYopo5SnAwAOXO 9Ui71TR+TGy6QSVKqWdzA== X-UI-Out-Filterresults: notjunk:1;V01:K0:Kg0+Y1/j27o=:f7mP5b1Qkc2ZyTxMRpAYl1 fhczF5uWUHMaT5DkHP1ITunsi058spzS8JzP9MpNvsvwdnW6jGf5yUFm4H9K8LaWCNgDj2G1u CPPOWWjM3V8TgNZXorS+q5GsFt/RDfQf3sBnKgtmaqqCntX4c0juoZNf+97NM6YB6FFfw/ty2 Wl3n6BziAiBKi7b6clATbXXpA90jAA1BJ7kkd4HGp9D3BlgfFr7juDKWQO6bEQ/G0kdq67eyY LLP1xsxH/+QKrvk4NT3MkPf2YgCDJuACx5dywORZGIPHX4KlGkk8FO4um6D+lzBy2O4VJ3X4w dX1tnDUUnc/8YjCNbyxPLLm4P2OIHqQjQMb08LVHuYWSIEzB+HOrL6RKls1YtE2M+QELbUdW+ 0wTs0lIa1KeapHHineNOnszsTn1M+3aD39DGBygPTS2LHEIjs/YuQunf7fjurticYBA16K5p3 +vU9/dPbajy6XxIxvgO+37dARJRP8335ThK1fZ1je3oPc02vYR+hJrJxbWAqx9VD3EiOGBLS3 4Jv6O0WhUScD17fC7nCG+zwLmu9ZtsEf1g6zs1YR0MCUHol0mwUWjuXmpbLMZukVPXCo+ulIK ASsWZIH00Pg9FlCZqdxTMe3i/ZNprYwX70bK7k6jtkGi1iaAcF/Mt/BgWrLY5sIe5Zfvju/CZ +sHonBs9WgdYjcs5ZpTfp5sFD5/rEpB9xg7RdfzLEvkFWJPNyYzk5B79pXlpSkkW3tV5ApUKq oo9fBkKfxq/012F37SJhJFXUbQ5GTdNR63/5ZoUHwtrYMMK2AWJ5vdr5pX4LZgMjwiSHe4vgq 3IfFnzF Subject: Re: [PHP-DEV] [Discussion] is_string(), string type and objectsimplementing __toString() From: cmbecker69@gmx.de ("Christoph M. Becker") On 09.03.2017 at 21:09, Rowan Collins wrote: > On 08/03/2017 23:32, Andrey Andreev wrote: > >> For example, a Cookie object may have the cookie attributes (domain, >> path, etc.) as value objects, but they can easily be created from raw >> strings, while other types would be ambiguous. >> A similar effect could be desirable for HTTP headers. > > OK, now we have some concrete examples, thanks. I would say that in > these cases, what you actually want is a much tighter contract: not just > "can be converted to string", but "intended to be used in this context". > > It fits with what I was saying before about "if you can't name it, maybe > it isn't the right abstraction". In this case, you want to accept some > particular value objects but not, say, Exceptions - which are as useless > for your purpose as an integer, even though (string)$foo would work fine > on both. > > So you want objects that have promised to behave appropriately for this > context; that could be as simple as: > > interface HTTPHeaderObject { > public function __toString(); > } > > ....with appropriate documentation that objects declaring that they > implement this interface promise to behave in a specific way when cast > to string. This is much clearer than detecting __toString(), which only > promises "I can be cast to string" - the same promise that is made by > all scalar values. > > In order to accept this or a string in a type hint, you need Union Types: > > function setHeaderValue(string|HTTPHeaderObject $value) { ... Or you could require the client to pass a respective string wrapper which extends HTTPHeaderObject instead of a plain string. -- Christoph M. Becker