Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98446 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 68540 invoked from network); 8 Mar 2017 22:43:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Mar 2017 22:43:58 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@fleshgrinder.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=php@fleshgrinder.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fleshgrinder.com from 77.244.243.82 cause and error) X-PHP-List-Original-Sender: php@fleshgrinder.com X-Host-Fingerprint: 77.244.243.82 mx101.easyname.com Received: from [77.244.243.82] ([77.244.243.82:34654] helo=mx101.easyname.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C9/6D-06022-D2980C85 for ; Wed, 08 Mar 2017 17:43:57 -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 1clkJG-0003WJ-Gx; Wed, 08 Mar 2017 22:43:54 +0000 Reply-To: internals@lists.php.net References: To: Andrey Andreev , Rowan Collins Cc: "internals@lists.php.net" Message-ID: Date: Wed, 8 Mar 2017 23:43:50 +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-DNSBL-PBLSPAMHAUS: YES Subject: Re: [PHP-DEV] [Discussion] is_string(), string type and objects implementing __toString() From: php@fleshgrinder.com (Fleshgrinder) On 3/8/2017 11:24 PM, Andrey Andreev wrote: > Hi again, > > On Wed, Mar 8, 2017 at 9:39 PM, Rowan Collins wrote: >> >> I think it comes down to what you're trying to achieve: the language can't >> have pseudo-types for every possible combination of types, so if you want to >> detect integers as one case, and other things that can be converted to >> string as another, just perform your checks in the right order: >> >> if ( is_int($foo) ) { >> // ... >> } elseif ( is_stringable($foo) ) { >> // ... >> } >> > > This is why I was concerned about the discussion becoming too broad - > it brings us (or me anyway) back to square 1, if not even out of > bounds. I wanted the ability to do "string or string object" checks > without multiple function calls, and now the suggested solution > doesn't do that. > > I do agree that we can't have pseudo-types for everything, but can we > at least have meaningful ones? How would "stringable" be different to > "string", and what's the point of either of them if they accept every > other scalar type? We're having this discussion because outside of the > so called "strict mode", PHP's string type is just as meaningful as > "scalar", which makes it useless IMO. > > Cheers, > Andrey. > What is the use case where every other scalar (and null) type is not acceptable? I defended that stringable should bridge only string and objects with __toString too first, but after thinking more about it, there is no real world reason why one would need that. Almost all use cases I can think about evolve around strict mode and some function that simply does not care what it was. Hence, stringable would truly act like the into trait in Rust. Although, to be fair, Rust does not provide Into nor Into<&'a str> for numeric types. I actually don't know why, since fmt::Display is implemented for all of them. Then again, Rust is very, very different to PHP. -- Richard "Fleshgrinder" Fussenegger