Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98478 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50485 invoked from network); 11 Mar 2017 11:39:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Mar 2017 11:39:36 -0000 Authentication-Results: pb1.pair.com header.from=php@fleshgrinder.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=php@fleshgrinder.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fleshgrinder.com from 77.244.243.86 cause and error) X-PHP-List-Original-Sender: php@fleshgrinder.com X-Host-Fingerprint: 77.244.243.86 mx105.easyname.com Received: from [77.244.243.86] ([77.244.243.86:45675] helo=mx105.easyname.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1F/80-38004-5F1E3C85 for ; Sat, 11 Mar 2017 06:39:34 -0500 Received: from cable-81-173-135-7.netcologne.de ([81.173.135.7] helo=[192.168.178.20]) by mx.easyname.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1cmfMx-0008Qu-7g; Sat, 11 Mar 2017 11:39:32 +0000 Reply-To: internals@lists.php.net References: <24efb0e7-b0e3-68ed-5f42-2d5481f8f291@gmail.com> <44add374-6c4b-399a-c542-8d7f100dfaa3@fleshgrinder.com> <2AB030D8-9677-4E0E-8215-07D77910E51B@gmail.com> To: Rowan Collins , Andrey Andreev Cc: "internals@lists.php.net" Message-ID: Date: Sat, 11 Mar 2017 12:39:20 +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: <2AB030D8-9677-4E0E-8215-07D77910E51B@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-DNSBL-PBLSPAMHAUS: YES Subject: Re: [PHP-DEV] [Discussion] is_string(), string type and objects implementing __toString() From: php@fleshgrinder.com (Fleshgrinder) On 3/10/2017 11:57 AM, Andrey Andreev wrote: > 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. I am totally in favor of strict types, but having a union of some type and having the ability to constraint to it is strict. The union of bool|int|float|null|string is stricter than the super type mixed. That's the whole point of having a stringable. You can more clearly communicate what you require to do your work. Once more, it does not matter what the caller give you, you need to validate it no matter what. On 3/10/2017 4:11 PM, Andrey Andreev wrote: > You don't, but I do care at times. Sorry, but your example makes no sense at all. Just because you got an int does not even remotely mean that one of those constants was used. On top of that all, you still need to validate the int you got because it has 2^31-1 possible states, or more in case of 64bit. You need an enum in such a case, and that's the only thing that helps, nothing else. It is also inherently simple to create one, and be type safe forever. -- Richard "Fleshgrinder" Fussenegger